Version 2 of Everything is a Symbol

Updated 2014-08-15 02:56:42 by AMG

In Tcl, Everything is a Symbol, and these symbols are represented by strings, giving rise to the Everything is a String slogan. The name of each command is a symbol which resolves to the command itself, and the arguments that are passed to a command are pure symbols, no strings attached: The command can interpret them any way it likes.

Each command is an independent domain, and the symbols it initially receives take on some meaning specific to that domain. In other words, each command speaks some domain-specific language, and the commands in a script are only connected by the protocol that each must return a single value.

Why is it not sufficient to say that everything is a string, and leave it at that? Because the string itself is meaningless without some kind of interpretation. From the operational perspective of Tcl itself as it dances between the commands, everything is just a string, and all it is doing is interpolating values and resolving commands, but the vast majority of activity within a script takes place inside the commands, where the strings take on additional meaning, and are treated in particular ways based on their interpretation. Everything is a string and everything is a symbol go hand in hand, describing the overal operation of Tcl in a golden braid of interleaved processing.

Tcl is the most pure language for symbolic computation . Lisp comes close, but its data objects are typed, making it one step less pure than Tcl in this context. One consequence of this pure symbolic approach is thatnumerical computation must be performed by a procedure dedicated to that domain rather than by the language proper. The most common tool for this is the venerable expr, but it is also possible to pass symbols directly to individual numerical operators, e.g. [+ 2 3], composing more complex expressions directly in Tcl via substitution:

* [+ 2 3] [+ 3 5]

This is efficient because the numeric interpretation of each + command is cached in the internal metadata for the substituted value, so that the outer * command can re-use it.

See Also

Symbolic manipulation
an experiment by Arjen Markus on computing the derivative of a function

Page Authors

PYK