Everything is a Symbol

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 that numerical 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

aspect: What's the purpose of this page? In Tcl we talk about EIAS and about words, not symbols. The text above plays fast and loose with the https://en.wikipedia.org/wiki/Symbol_%28programming%29%|%accepted CS definition of a symbol and makes a specious comparison with Lisp. Nothing is clarified .. it seems only an exercise in multiplying entities. While such germs of philosophical omphaloskepsis can be interesting in their own right, I don't think this merits a wiki page.

PYK 2014-08-14:

EIAS operates at one level, but understanding that those strings are symbols that have arbitrary interpretations is one of the keys to appreciating the unique nature of Tcl. This page is in part a response to definitions of "symbol" like those in the Wikipedia article you linked to. Other Languages are constrained by an arbitrary distinction between symbols and literals. In Tcl, this distinction melts away.

Linguistically, a word is a symbol, and humans are so familiar with words as symbols that it's hardly necessary to point the fact out, but deconstructing and examining a language system leads to a need to name the components, patterns, and behaviours at play. It's metadiscussion, and necessary for detailed understanding. Tcl is minimal, almost a set of language primitives rather than a full language. It's worth describing the divide between the script level where Tcl is methodically processing words without assigning meaning, and the domain-specific universe of each command, where semantic interpretation happens. For one thing, it's rather unique to Tcl. What other language has eliminated symbols from its syntax, thereby turning everything into a symbol?

Describing words as symbols helps to explain the structure that is used to represent them in the implementation language of Tcl, and which ties the string representation of the value to a cached internal representation that is more concrete and computable. As the symbols pass out of one domain-specific universe, through the Tcl script-processing system, and into another, the cached representation may get re-used, or it may be discarded in favour of some new interpretation. This dual-ported nature of values exists precisely because everything is a symbol.

https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Statues_at_the_Louvre.jpg/640px-Statues_at_the_Louvre.jpg