next up previous index
Next: Comments Up: Basic Tcl Previous: Quoting with Braces

Data

Tcl knows only one data type, namely strings. However, numeric strings are interpreted as numbers wherever appropriate.

Lists are similar to lists in Prolog, except that   they are represented as strings and whitespace separators are significant for them. It does not matter if lists are grouped together with double quotes or braces (except for substitutions):

% if {{a b c} == "a b c"} {puts yes} {puts no}
yes
however there are subtle differences:
% puts {}

% puts ""

% puts {{}}
{}
% puts {""}
""
% puts "{}"
{}
The main difference between lists and strings is that lists can be nested whereas strings are flat. A string is interpreted as a flat list whenever appropriate, list elements are separated by whitespace characters. The list separators are kept verbatim in the list:
% set a {a    {  b  c } d}
a    {  b  c } d
% string compare {a } { a}
1

Lists with one element are identical to atoms, so e.g. a and {a} are identical:

% string compare a {a}
0
Such lists can be explicitly created by double braces:
% puts {{a}}
{a}
Even around braces, spaces are significant:
% llength {{a b}{c d}}
list element in braces followed by "{c" instead of space
% llength {{a b} {c d}}
2


Micha Meier
Tue Jul 2 09:49:39 MET DST 1996