tcl Dictionaries


Dictionaries in Tcl are values that hold a mapping from arbitrary values to other arbitrary values. They were introduced in Tcl 8.5, though there are limited versions for (the now unsupported) Tcl 8.4. Dictionaries are syntactically the same as lists with even numbers of elements; the first pair of elements is the first key and value of the dictionary, the second pair is the second tuple.


fox "quick brown" dogs "lazy"

is a valid dictionary. The same key can be multiple times, but it is exactly as if the latter's value was in the earlier's value; these are the same dictionary:

abcd {1 2 3} defg {2 3 4} abcd {3 4 5}
abcd {3 4 5} defg {2 3 4}

Whitespace is unimportant, just as with lists.

An important concept with dictionaries is iteration order; dictionaries try to use the key insertion order as their iteration order, though when you update the value for a key that already exists, you overwrite that key's value. New keys go on the end.

References: dict