'''Is Tcl Different!''' enumerates what makes '''T'''he '''c'''ool '''l'''anguage special ** See Also ** [Stephen Uhler's HTML parser in 10 lines]: [Tcl heritage]: [Arts and crafts of Tcl-Tk programming]: [Tcl/Tk is too easy]: [Bag of Algorithms]: [Bag of Tk algorithms]: [Braintwisters]: [Tcl Gems]: ** Description ** '''Uniqueness''': Tcl is designed to be the ultimate all-purpose scripting tool, and this is what it won the [https://awards.acm.org/software-system%|%ACM Software System] award for. Tcl has the unique ability to be nearly any other [programming language] or system. It is an all-purpose skin that easily stretches over other systems. Tcl's untyped values make it richer by liberating it from the dictates of complex type systems. Each value takes on whatever meaning the [routine%|%routine] that receives it assigns to it. '''Simplicity''': The [dodekalogue%|%rules of Tcl] are minimal. Apart from the eight special characters, there are only [word%|%words] and [command%|%commands]. [list%|%Lists] are simply strings, with words in a list delimited by whitespace. This simplicity facilitates the creation of simple and readable scripts. See [Salt and Sugar] for one example. It is easy to create a bidirectional pipeline to another system process: `[set] p [[[open] |foo r+]` . '''Unity of data and code''': [list%|%Lists] and [script%|%scripts] have a symbiotic relationship where every list is syntactically a [command]. This makes it possible to use the language of Tcl in creative ways. It is common to [code generation%|%generate code] for the interpreter to [eval%|%evaluate]. Other more exotic techniques include [Config file using slave interp%|%using a slave interp to parse configuration files], and [deep list%|%deep lists] as a [data format%|%format for structured data]. '''Dynamic Introspection''': `[info vars]`, `[info commands]`, `[info procs]` retrieve lists of objects exsisting in the interpreter. `[info args]`, `[info default]`, and `[info body]` retrieve the argument specification, default values, and body for a procedure. [Widget%|%widgets] report their own configuration. `[upvar]` accesses variables at any [level], and `[uplevel]` evaluates a scripts at any level. '''Minimal parsing''': Less syntax means fewer decisions for the interpreter to make, and gives routines flexibility to shape the functionality of a particular script. [expr], [regexp], [scan], and [glob] all to coexist happily, each implementing its own [little language]. '''untyped values''': A value can be treated as a string one moment, a list in the next moment, and a number a moment conversions. This can be used to produce simple readable scripts. One might, for example, add a list of numbers with `expr [[[join] $list +]`. Of course, one should remain aware of [double substitution] and of the potential performance cost of [shimmering]. '''Internationalization''': Each value is a [Unicode] string. [Tk%|%Tk's] mechanism for finding a Unicode character in other fonts is extremely helpful when you go global. See [The Lish family] for helpers from 7-bit ASCII to Unicode characters. '''User-friendliness''': Even most Tcl error messages are kind of a joy to read - endless loops (recursions) aren't endless anymore but detected and reported. Most commands are implemented in a pretty common-sense, evident way. Various channels are available when looking for [Getting help%|%a little advice]. '''Power''': This extremely flexible language makes it possible to do more with less. [string%|%String] manipulation, [eval%|%evaluation], the [Tcl event loop%|%event loop] can be combined to great effect in a few lines of code. Features like `[unknown]` make possible things like [Radical Language Modification]. Examples of this power include Stephen Uhler's [HTML] parser in 10 lines and [A little checker game%|%an interactive checkerboard] in 44 lines. '''Clarity''': [Perl], in contrast, is hard to understand. For instance, the Perl man pages contain 493 occurrences of the word "magic" - used when the details are too overwhelming to fully explain - it's easier to just say "the right choice will be made, it's magic, trust us". Even the Programming Perl book uses words like magic, incantations, etc, all over, which is startling considering that it's supposed to be a reference. In contrast, the Tcl documentation contains zero uses of magic or anything remotely suggesting something is going on behind the curtains that is simply too hard to grasp. The Perl source echoes this inability to explain the details and contains over 400 occurrences of the word "magic. The Tcl source contains none and in fact is beautifully documented. '''[Tk]''' is the best, easiest [GUI] scripting toolset around.: [Perl] and [Python] also use it, even if they have to emit some Tcl code for that. But the freshest Tk is always bundled with Tcl. '''[Expect]''' is the best, easiest tool around for automating, testing or [gluing] interactive programs.: Even Perl, Python, and [Java] experts prefer Expect over trying to do the same thing in other languages. ---- HD: Another point: there are obfuscated [C] contests and obfuscated Perl contests, and half the activity in cplm seems to be about posting incredibly obscure one-lines that print out "just another perl hacker", but when's the last time someone boasted of their obfuscated Tcl code? [DGP]: Why on the [Obfuscation] page, of course! ---- [RS]: Just yesterday I glanced at an older GC[LISP] manual - they have more than two dozen types to choose from. Or [Java]'s class hierarchy, where it takes many minutes just to see what's all there. With Tcl it's different: you don't have a monster toolbox to wonder at, just knife, fork, spoon - and yumm!, off you go! ;-) ---- [RS]: one more thought: Programming languages of old had arithmetics and I/O operations as central elements. Came C and said, "I/O is not part of the language, use libraries for that" (and only had to allow varargs for printf). Some years later came Tcl and said, "Arithmetics is not part of our language either, use specialized commands, e.g. [expr]", leading to a substantial simplification again. Q: can this trend be continued - are there parts in Tcl that may be defined out (without loss of expressivity)? Or is Tcl essentially essential? CL replies: the cheap answer is, yes, of course, $-dereferencing is purely epiphenomenal [[deref ref]]. [DKF]: Tcl's core syntax is actually insufficient to be a full programming language; it's not inherently Turing Complete. To get there, you have to add some commands (not many though; with `[expr]`, `[set]` and `[while]` you could do a (bounded-tape) TM relatively easily). [sergiol]: [DKF] Why do you say it is not Turing complete? [AMG]: [DKF] is drawing a distinction between the Tcl core syntax and the Tcl command library. The Tcl syntax has no branching and looping capabilities; those are provided by the [[[if]]] and [[[while]]] commands. While it can get the value of a variable using `$`, it cannot set it without a command such as [[[set]]]. ** Page Authors ** [PYK]: Revised the original contents. [Richard Suchenwirth]: <> Advocacy