All ColdC data has a type and a logical truth value it will return when evaluated as an expression. The following is a list of ColdC data types along with their names and literal representation in ColdC:
| Type | Name | Representation |
|---|---|---|
| Integer | 'integer | 42 |
| Float | 'float | 1.0 |
| String | 'string | "This String" |
| Buffer | 'buffer | `[13, 10] |
| Symbol | 'symbol | 'identifier |
| List | 'list | [1, 2, 3, 4] |
| Object Number | 'objnum | #1234 |
| Object Name | 'objname | $identifier |
| Dictionary | 'dictionary | #[["key", $value]] |
| Error Code | 'error | ~identifier |
| Frob | 'frob | <object, value> |
The type of data being manipulated can be determined using the type() function.
Integer
An integer is a rational number (in mathematical terms). Integers can reliably be from 2147483647 to -2147483648 (unless the driver has been compiled with BIG_NUMBERS, in which case they are larger). An integer is logically true if it is not zero (negative numbers are logically true). Integers are denoted in ColdC with a series of digits, optionally preceded with a plus (+) or minus (-) sign.
See also: Numeric Functions
Float
A float is a real number (in mathematical terms). A float is logically true if it is not zero. Floats are denoted in ColdC with two numbers separated by a period and optionally preceded with a plus (+) or minus (-) sign. If the float has small enough precision it may be formatted in scientific notation. Both forms are acceptable. For instance, the two floats are equivalent:
0.000000001
1e-09
See also: Numeric Functions
String
A string is a sequence of printable characters. A string is logically true if it is not empty. A string is denoted in ColdC by enclosing the printable characters within double quote characters ("). To include a double quote inside a string precede it with a backslash (\\). Any other occurrence of a backslash in a string has no special meaning. The following are some examples of strings:
"foo"
"\"foo\" is a metasyntactic variable."
"The backslash ('\') is a much-abused character in many languages."
See also: String Functions
Symbol
A symbol is similar to a string, but it has been abstracted into a ColdC identifier. This makes comparisons between symbols much faster than with strings. When comparing a string, each character in the string must be compared, but only one comparison occurs when comparing a symbol. Symbols are denoted in ColdC by preceding the identifier with an apostrophe ('). Symbols are not terminated with an apostrophe. Symbols are always logically true.
List
A list is an ordered grouping of data. The data contained within a list can be of any type and does not have to be the same type throughout the list. Lists are useful for grouping different data elements together. A list is logically true if it contains one or more elements and is logically false if it is empty. A list is constructed by enclosing a comma-separated series of data elements within square brackets. For example both of the following are both valid lists:
[1, 2, 3]
[1, ["foo", 'bar], $sys]
See also: List Functions
Object Number and Object Name
Object numbers and object names are explained in detail in the section Referencing Objects. Object numbers and names are always logically true.
Dictionary
A dictionary is a collection of data associations, each of which has a key and a value. Dictionaries are similar to lists. However, lookup in a dictionary is with the key (returning the value) rather than with the location in the list. Dictionaries generally take up more storage space in memory than lists, and are slightly slower to add to and remove from than lists. But searching for items in dictionaries is much faster than searching for items in a list.
Dictionaries are denoted by a list of two-element lists, preceded with a hash mark (#). Each of the two-element lists is an association, where the first element is the key and the second element is the value. Dictionaries are logically true unless empty. The following are valid dictionaries:
#[["foo", 3], ['bar, 'baz]]
#[["something", 'blue], ["one", 1], ["two", 2]]
When evaluating the key for the value in the dictionary is indexed, rather than the position as in a list, such as:
dict = #[["foo", 3], ['bar, 'baz]];
dict['bar];
=> 'baz
See also: Dictionary Functions
Error Code
An error code identifies an error. Both the ColdC interpreter and ColdC methods use error codes to identify types of errors when they occur. See Errors for information about how errors in ColdC are handled. Errors are denoted in ColdC by preceding an identifier with a tilde (~). Error codes are always logically false.
Frob
Frobs are an abstract data type used for dynamically handling data when using it as the receiver of a method call expression. Normally, when data is used as the receiver for a method call, the interpreter will actually lookup and use an object with an object name that is the same as the type of data being used (such as the object $string if the data is a string). In the case of a frob, the receiver is specified within the frob as the frob class. Frobs also give the ability to specify a special method with which to handle the call.
Frobs are useful for grouping, abstracting, and encapsulating a set of similar data by associating it with a handler object. Frobs are constructed by enclosing the class and representation within a less-than sign (<) and a greater-than sign (>), separated by a comma. All of the following are valid frobs:
<$thing_frob, #[['desc, "worthless"], ['name, "coin"]]>
<$coins, [923]>
<#73, [1, 2]>
The frob's usefulness becomes apparent when it is used as the recipient in a method-call expression. In this instance the frob class becomes the recipient and the frob value becomes the first argument sent to the method. For instance, the following two method calls are equivalent:
(<$list, [1, 2, 3]>).reverse('do_this)
$list.reverse([1, 2, 3], 'do_this)
Furthermore, if a handler is used, the handler is called as the method, and the expected method is sent as a symbol argument. The following two method calls are equivalent:
(<$obj, #[], 'handle_it>).tell("foof")
$obj.handle_it(#[], 'tell, "foof")
Because of the difference in how a frob method is called, it is possible to define a method as a frob-only method. If a method is defined as a frob-only method it is only called when called by a frob. Calling it in the standard syntax would not retrieve the frob-only method, but would instead look for a method with the same name further up the ancestor hierarchy. For more information see Frobbed Methods.
Frobs are always logically true.
See also: frob_class(), frob_value(), and frob_handler()
Buffer
A buffer is an array of integers which are interpreted to unsigned eight-bit values. Keep this in mind, as the range of an integer in a buffer is only 0 through 255. Any other number will be randomly cast to an eight bit unsigned value.
Buffers are intended for handling character values outside of the normal printable range used by ColdC strings. A buffer is constructed by prefixing a list of integers with an accent mark (`), where each integer is the decimal value of the respective character. Buffers are logically true if not empty. The following buffer and string are equivalent:
`[98, 117, 102, 102, 101, 114]
"buffer"
See also: Buffer Functions