/
ColdC/Functions/
ColdC/Structure/
<head><title>ColdC: Language Structure: Data Types</title></head>

<body>
<h1 align=center><a href="/ColdC/">ColdC</a>: <a href="/ColdC/Structure/">Language Structure</a>: Data Types</h1>

<hr>

<p>All ColdC data has a type and a logical truth value it will take on when
evaluated as an <a href="expressions.html"><i>expression</i></a>.  The following is
a list of ColdC data types along with their names and literal representation
in ColdC:</p>
<pre>
<b><i>     Type            Name          Representation</i></b>

     Integer         'integer      42
     Float           'float        1.0
     String          'string       "This String"
     Symbol          'symbol       'a_symbol
     List            'list         [1, 2, 3, 4]
     Object Number   'objnum       #1234
     Object Name     'objname      $sys
     Dictionary      'dictionary   #[["key", $value], [1, "value"]]
     Error Code      'error        ~error
     Frob            'frob         &lt;object, value&gt;
     Buffer          'buffer       `[]
</pre>

<p>The type of data being manipulated can be determined using the
<a href="/ColdC/Functions/type.html"><code>type()</code></a> function.</p>

<a name=integer><h2>Integers</h2></a>

<p>An <i>integer</i> is simply a number.  Integers can reliably be from
2147483647 to -2147483648.  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 (<code>+</code>)
or minus (<code>-</code>) sign.</p>

<a name=float><h2>Floats</h2></a>

<p>A <i>float</i> is simply a floating point number.  A float is logically
true if it is not zero.  Floats are denoted in ColdC with two numbers
seperated by a period and optionally preceded with a plus (<code>+</code>)
or minus (<code>-</code>) sign.</p>

<a name=string><h2>Strings</h2></a>

<p>A <i>string</i> is a sequence of printable characters.  A string is
logically true if it is not empty.  A string is denoted in ColdC by
enclosing a sequence of printable characters within double quotes
(<code>"</code>).  To include a double quote inside a string precede it
with a backslash.  In all other instances a backslash has no special meaning.
The following are some examples of strings:</p>

<blockquote><pre>
"foo"
"\"foo\" is a metasyntactic variable."
"The backslash (`\') is a much-abused character in many languages."
</pre></blockquote>

<a name=symbol><h2>Symbols</h2></a>

<p>A <i>symbol</i> is a symbolic value, represented by an identifier.
Symbols are denoted in ColdC by preceding the identifier with an apostrophe
(<code>'</code>).  When used in a lookup or matched relationship, symbols
are equivalent to matching integers, whereas strings still require checking
each character to verify a match.  Symbols are not terminated with an
apostrophe.  Symbols are always logically true.</p>

<a name=list><h2>Lists</h2></a>

<p>A <i>list</i> 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 througout the list.
Lists are useful for manipulating several pieces of data at once. A list is
logically true if it is not empty. You can construct a list value by
enclosing a comma-separated series of data in square brackets; for example,
<code>[1, 2, 3]</code> and <code>[1, ["foo", 'bar], $sys]</code> are valid
lists.</p>

<a name=objnum><a name=objname><h2>Object Numbers and Names</h2></a></a>

<p><i>Object numbers</i> and <i>object names</i> are explained in detail,
in the section on Objects: <a href="/ColdC/Objects/referencing.html">Referencing
Objects</a>.  Object numbers and names are always logically true.</p>

<a name=dict><h2>Dictionaries</h2></a>

<p>A <i>dictionary</i> 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 take up more space than lists,
but lookup in dictionaries is generally faster than lookup in a list.</p>

<p>Dictionaries are denoted by a list of two-element lists, preceded with a
hash mark (<code>#</code>).  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 all valid
dictionaries:</p>

<blockquote><pre>
#[["foo", 3], ['bar, 'baz]]
#[["something", 'blue], ["one", 1], ["two", 2]]
</pre></blockquote>

<p>If you were to assign the first dictionary to a variable by the name
of <var>dict</var>, the expression <code>dict['bar]</code> would return
<code>'baz</code>.

<a name=error><h2>Error Codes</h2></a>

<p>An <i>error code</i> identifies an error.  Both the ColdC interpreter
and ColdC methods use error codes to identify types of errors when they occur.
See section <a href="/ColdC/errors.html">Errors</a> for information about how
errors in ColdC are handled.  Errors are denoted in ColdC by preceding
an identifier with a tilde (<code>~</code>).  Error codes are always logically
false.</p>

<a name=frob><h2>Frobs</h2></a>

<p><i>Frobs</i> are an advanced data type in ColdC.  They consist of
a <i>class</i> (the controlling object) and a <i>representation</i> (a
list or dictionary).  Frobs are intended to serve as lightweight objects.
Frobs are constructed by enclosing the class and representation within
a less-than sign (<code>&lt;</code>) and a greater-than sign
(<code>&gt;</code>), seperated by a comma.  All of the following are
valid frobs:</p>

<pre><blockquote>
&lt;$thing_frob, #[['desc, ["something small"]], ['name, "a small thing."]]&gt;
&lt;$coins, [923]&gt;
&lt;#73, [1, 2]&gt;
</pre></blockquote>

<p>When a frob is used in a method-calling expression, as the object, the
method is called on the frob class, with the first argument being the
frob representation, followed by subsequent arguments.  The following are
rougly equivalent:</p>

<pre><blockquote>
(&lt;$list, [1, 2, 3]&gt;).reverse()
$list.reverse([1, 3, 3])
</pre></blockquote>

<p>Frobs are always logically true.</p>

<a name=buffer><h2>Buffers</h2></a>

<p>A <i>buffer</i> is an array of unsigned eight-bit values, intended for
handling character values outside of the normal printable range used by
ColdC strings. You can construct a buffer by prefixing a list of integers
with an accent mark (<code>`</code>).  For instance, the buffer
<code>`[98, 117, 102, 102, 101, 114]</code> is equivalent to the string
<code>"buffer"</code>.  Buffers are logically true if not empty.</p>

<h2>Equivalent Types</h2>

<p>The following is a list of ColdC data types along with relative data
types from other languages which may be more familiar.</p>
<pre>
     <b>ColdC</b>                                   <b>ANSI C</b>
     -----                                   ------
     Integer        1                        Integer         1
     Float          1.0                      Float           1.0
     String         "String"                 String          "String"
     Symbol         'Symbol
     List           [1, 2, 3]                Array           {1, 2, 3}
     Object Number  #1234
     Object Name    $sys
     Dictionary     #[["key", $value]]
     Error          ~error
     Frob           &lt;object, value&gt;
     Buffer         `[]

     <b>ColdC</b>                                   <b>MOO</b>
     -----                                   ---
     Integer        1                        Integer         1
     Float          1.0
     String         "String"                 String          "String"
     Symbol         'Symbol
     List           [1, 2, 3]                List            {1, 2, 3}
     Object Number  #1234                    Object          #1234
     Object Name    $sys
     Dictionary     #[["key", $value]]
     Error          ~error                   Error           ERR_...
     Frob           &lt;object, value&gt;
     Buffer         `[]

     <b>ColdC</b>                                   <b>Pascal</b>
     -----                                   ------
     Integer        1                        Integer         1
     Float          1.0                      Real            1.0
     String         "String"                 String          'String'
     Symbol         'Symbol
     List           [1, 2, 3]                array           &lt;unexpressable&gt;
     Object Number  #1234
     Object Name    $sys
     Dictionary     #[["key", $value]]
     Error          ~error
     Frob           &lt;object, value&gt;
     Buffer         `[]

     <b>ColdC</b>                                   <b>Perl</b>
     -----                                   ----
     Integer        1                        Integer         1
     Float          1.0                      Float           1.0
     String         "String"                 String          "String"
     Symbol         'Symbol
     List           [1, 2, 3]                List            (1, 2, 3)
     Object Number  #1234
     Object Name    $sys
     Dictionary     #[["key", $value]]       Hash            %(1, 2)
     Error          ~error
     Frob           &lt;object, value&gt;
     Buffer         `[]

     <b>ColdC</b>                                   <b>LISP</b>
     -----                                   ----
     Integer        1                        Integer         1
     Float          1.0                      Float           1.0
     String         "String"                 String          "String"
     Symbol         'Symbol
     List           [1, 2, 3]                Vector          (1 2 3)
     Object Number  #1234
     Object Name    $sys
     Dictionary     #[["key", $value]]
     Error          ~error
     Frob           &lt;object, value&gt;
     Buffer         `[]
</pre>
<hr size=4><p align=center><i>Last Modified on Jan 25 1996</i>
<br><i>Copyright &copy; 1995, 1996, Brandon Gillespie</i>
</body>