Next: Names

Data Types

Every piece of data in C-- has a type. This section documents the data types in C--. You can produce values of the simpler data types (integers, strings, dbrefs, symbols, error codes) can be produced with literal expressions; you can produce values of the more complex data types (lists, dictionaries, frobs, buffers) with constructor expressions. As we go, we will explain how to specify or construct values of each of the data types, and explain what it means for a value of each data type to be true.

Every piece of data in C-- has a type and a truth value. The type can be one of:

An integer is just a number. Integers can reliably be from -2147483648 to +2147483647. An integer is true if it is not zero. You can denote integer literals in C-- by writing a sequence of digits, optionally preceded by a - or + sign.

A string is a sequence of printable characters. A string is true if it is not empty. You can denote string literals in C-- by enclosing a sequence of characters in double quotes ("). To include a double quote or backslash character in a string literal, precede it by a backslash (\). The following are string literals:

"foo"
"\"foo\" is a metasyntactic variable."
"The backslash (`\\') is a much-abused character in many languages."
A dbref is a reference to an object, which may or may not exist. Database references are always true, whether or not they refer to actual objects. You can denote dbref literals in C-- by preceding a number with a sharp (#); for example, #1 and #267 are valid dbref literals.

A list is a collection of objects of any type. Lists are useful for manipulating several objects at once. A list is true if it is not empty. You can construct a list value by enclosing a comma-separated series of expressions in square brackets; for example, [1, 2, 3] and [1, ["foo", 'bar], #23] are valid list construction expressions.

A symbol is a symbolic value. You can denote symbols in C-- by preceding an identifier or string with an apostrophe ('). 'remote, 'template, and 'object are valid symbol literals. Symbols are always true.

An error code identifies a type of error condition. Both the C-- interpreter and C-- methods use error codes to identify types of errors when they occur. See Errors for information about how Coldmud handles errors. You can denote error code literals in C-- by preceding an identifier or string with a tilde (~). Error codes are always false.

A frob consists of a class, the dbref of an object, and a representation, a list or dictionary. Frobs are intended to serve as lightweight objects. You can construct a frob value by enclosing expressions for the class and representation in triangular brackets, separated by a comma; for instance, <#73, [1, 2]> is a valid frob construction expression. Frobs are always true.

A dictionary is a collection of associations, each of which has a key and a value. Dictionaries take up more space than lists, but searching for a data value in a dictionary is generally faster than searching for data values in lists. You can construct a dictionary by enclosing a comma-separated series of associations in square brackets, where each association is a two-element list giving a key and a value, and preceding the whole thing with a hash mark (#). For instance, #[["foo", 3], ["bar", 'baz]] is a valid dictionary construction expression. A dictionary is true if it is not empty.

a buffer is an array of unsigned eight-bit values, intended for network I/O. You can construct a buffer by enclosing a comma-separated series of integer expressions in square brackets, preceded by a percent sign (%). For instance, %[65, 66, 67, 10] is a valid buffer construction expression. A buffer is true if it is not empty.

You can get the type of a piece of C-- data using the type() function. The type() function returns a symbol corresponding to the type of its argument. This symbol can be 'integer, 'string, 'dbref, 'list, 'symbol, 'error, 'frob, or 'dictionary.