Tcl(3tcl)

πŸ‘‘ Tcl(3tcl) β€” Tcl Built-In Commands πŸ‘‘

okay bestie, welcome to the Tcl page πŸ’– this is the Tcl Built-In Commands manual, and we’re about to go through the whole syntax like it’s a group chat. no cap, this is part 1, so buckle up 🫢


πŸ’– NAME πŸ’–

Tcl - Tool Command Language. that’s the name, bestie, and it ate πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

Summary of Tcl language syntax. literally the TL;DR of the whole language syntax vibe ✨

✨ DESCRIPTION ✨

🧚 SYNTAX 🧚

okay so these rules? they define the syntax and semantics of the Tcl language. no skips, no shortcuts. periodt.

[1] Commands πŸ’¬

a Tcl script is just a string that has one or more commands in it. semicolons and newlines are command separators, unless you quote them like we talk about below. and close brackets? they are command terminators during command substitution (see below), unless quoted. it’s giving β€œseparators have main character energy.”

[2] Evaluation 🧠

when a command gets evaluated, it happens in two steps, bestie. step one: the Tcl interpreter breaks the command into words and does substitutions as described below. these substitutions happen the same way for all commands. step two: the first word is used to locate a routine to carry out the command, and the remaining words get passed to that routine. that routine is free to interpret each of its words however it wants β€” like an integer, variable name, list, or Tcl script. different commands interpret their words differently. iykyk.

[3] Words πŸ—£οΈ

words of a command are separated by white space. except newlines, because newlines are command separators. so no, newline is not just white space here, she’s a separator πŸ’…

[4] Double quotes πŸ’¬

if the first character of a word is a double-quote ("), then the word ends at the next double-quote character. if semicolons, close brackets, or white space characters (including newlines) show up between those quotes, they’re treated as ordinary characters and included in the word. command substitution, variable substitution, and backslash substitution all get performed on the characters between the quotes as described below. and the double-quotes themselves? not retained as part of the word. they’re just the vibe wrapper, not the vibe. periodt.

[5] Argument expansion πŸš€

if a word starts with {*} and then a non-whitespace character, the leading {*} gets removed and the rest of the word is parsed and substituted like any other word. after substitution, the word is parsed as a list (without command or variable substitutions; backslash substitutions are performed as is normal for a list, and individual internal words may be surrounded by either braces or double-quote characters), and its words are added to the command being substituted. for instance, cmd a {*}{b [c]} d {*}{$e f {g h}} is equivalent to cmd a b {[c]} d {$e} f {g h}. slay.

[6] Braces πŸŽ€

if the first character of a word is an open brace ({) and rule [5] does not apply, then the word is terminated by the matching close brace (}). braces nest within the word: for each additional open brace there has to be an additional close brace. (but if an open brace or close brace within the word is quoted with a backslash, it is not counted when locating the matching close brace). no substitutions are performed on the characters between the braces except for backslash-newline substitutions described below, and semicolons, newlines, close brackets, or white space do not get any special interpretation either. the word will consist of exactly the characters between the outer braces, not including the braces themselves. it’s giving β€œcontainment, but make it syntax.”

[7] Command substitution πŸ”

if a word contains an open bracket ([), Tcl performs command substitution. to do this, it invokes the Tcl interpreter recursively to process the characters following the open bracket as a Tcl script. that script may contain any number of commands and must be terminated by a close bracket (]). the result of the script (i.e. the result of its last command) is substituted into the word in place of the brackets and all the characters between them. there may be any number of command substitutions in a single word. command substitution is not performed on words enclosed in braces. no cap.

[8] Variable substitution πŸ’°

if a word contains a dollar-sign ($) followed by one of the forms below, then Tcl performs variable substitution: the dollar-sign and the following characters are replaced in the word by the value of a variable. variable substitution may take any of these forms:

  • $name β€” Name is the name of a scalar variable. the name is a sequence of one or more characters that are a letter, digit, underscore, or namespace separators (two or more colons). letters and digits are only the standard ASCII ones (0–9, A–Z and a–z). okurrr.
  • $name(index) β€” Name gives the name of an array variable, and index gives the name of an element within that array. Name must contain only letters, digits, underscores, and namespace separators, and may be an empty string. letters and digits are only the standard ASCII ones (0–9, A–Z and a–z). command substitutions, variable substitutions, and backslash substitutions are performed on the characters of index. obsessed.
  • ${name} β€” Name is the name of a scalar variable or array element. it may contain any characters whatsoever except for close braces. it indicates an array element if name is in the form arrayName(index) where arrayName does not contain any open parenthesis characters, (, or close brace characters, }, and index can be any sequence of characters except for close brace characters. no further substitutions are performed during the parsing of name. periodt.

there may be any number of variable substitutions in a single word. variable substitution is not performed on words enclosed in braces.

note that variables may contain character sequences other than those listed above, but in that case other mechanisms must be used to access them (e.g., via the set command's single-argument form). so if you’re feeling spicy with variable names, that’s the tea.

[9] Backslash substitution πŸͺ„

if a backslash (\) appears within a word, then backslash substitution occurs. in all cases but those described below, the backslash is dropped and the following character is treated as an ordinary character and included in the word. this lets characters like double quotes, close brackets, and dollar signs be included in words without triggering special processing. iconic, honestly.

the following table lists the backslash sequences that are handled specially, along with the value that replaces each sequence. (yes, table β€” we’re doing bullet table realness here, bestie.)

  • \a β€” Audible alert (bell) (Unicode U+000007). ding ding, bestie πŸ””
  • \b β€” Backspace (Unicode U+000008). not me erasing the vibe πŸ™ˆ
  • \f β€” Form feed (Unicode U+00000C).
  • \n β€” Newline (Unicode U+00000A).
  • \r β€” Carriage-return (Unicode U+00000D).
  • \t β€” Tab (Unicode U+000009).
  • \v β€” Vertical tab (Unicode U+00000B).
  • \<newline>whiteSpace β€” A single space character replaces the backslash, newline, and all spaces and tabs after the newline. this backslash sequence is unique because it is replaced in a separate pre-pass before the command is actually parsed. that means it will be replaced even when it occurs between braces, and the resulting space will be treated as a word separator if it is not in braces or quotes. it’s giving β€œpre-pass main character energy.”
  • \\ β€” Backslash (\).
  • \ooo β€” The digits ooo (one, two, or three of them) give an eight-bit octal value for the Unicode character that will be inserted, in the range 000–377 (i.e., the range U+000000–U+0000FF). the parser will stop just before this range overflows, or when the maximum of three digits is reached. the upper bits of the Unicode character will be 0.
  • \xhh β€” The hexadecimal digits hh (one or two of them) give an eight-bit hexadecimal value for the Unicode character that will be inserted. the upper bits of the Unicode character will be 0 (i.e., the character will be in the range U+000000–U+0000FF).
  • \uhhhh β€” The hexadecimal digits hhhh (one, two, three, or four of them) give a sixteen-bit hexadecimal value for the Unicode character that will be inserted. the upper bits of the Unicode character will be 0 (i.e., the character will be in the range U+000000–U+00FFFF).
  • \Uhhhhhhhh β€” The hexadecimal digits hhhhhhhh (one up to eight of them) give a twenty-one-bit hexadecimal value for the Unicode character that will be inserted, in the range U+000000–U+10FFFF. the parser will stop just before this range overflows, or when the maximum of eight digits is reached. the upper bits of the Unicode character will be 0.

backslash substitution is not performed on words enclosed in braces, except for backslash-newline as described above. so braces are like the VIP section where backslash substitution mostly doesn’t get in, except for that one special backslash-newline. periodt.


  1. Comments. β€” okay bestie, here's the tea β˜• if a hash character (#) shows up at a point where Tcl is expecting the first character of the first word of a command, then that # plus every character after it, all the way through the next newline, is treated as a comment and straight-up ignored πŸ’… and the comment character only matters when it appears at the beginning of a command β€” anywhere else it's just vibing as a regular character, no cap.
  2. Order of substitution. β€” every single character gets processed exactly once by the Tcl interpreter while it's building the words of a command. So, for example, if variable substitution happens, then no further substitutions get performed on the value of that variable β€” the value just gets inserted into the word verbatim, periodt. And if command substitution happens, then the nested command gets processed entirely by the recursive call to the Tcl interpreter β€” no substitutions are performed before making that recursive call, and no additional substitutions are performed on the result of the nested script. πŸ™ˆ

Substitutions go down left to right, and each one is evaluated completely before Tcl even attempts to evaluate the next one. So something like

set y [set x 0][incr x][incr x]

will always set the variable y to the value, 012. ✨

  1. Substitution and word boundaries. β€” substitutions do not affect the word boundaries of a command, except for argument expansion as specified in rule [5]. Like, during variable substitution the entire value of the variable becomes part of a single word, even if the variable's value contains spaces. 🫢

πŸ¦‹ TCL VALUES πŸ¦‹

Conceptually, all values in Tcl are strings β€” or, to be precise, sequences of Unicode code points. The way that every value is a string is commonly referred to as the Everything Is A String (EIAS) principle. πŸ‘‘

For the most part, Tcl strings can be thought of as strings of characters instead of sequences of code points, and following common usage, command descriptions refer to them as such. However, the distinction is worth noting, because some characters may have multiple representations as Unicode code point sequences, and in operations like comparisons, Tcl compares individual code points and not individual abstract characters. 🧚

So while all values are strings, individual commands may treat or expect their arguments to be representations of data of a particular type. For example, the incr command expects its operands to be integers. πŸ”’

The most important consequence of the EIAS principle is that all commands must treat arguments that have a particular string representation exactly the same irrespective of how that value was produced. Thus the incr command must treat 100 produced by appending 0 to 10 exactly the same as 100 produced by multiplying 10 by itself. πŸ’―

Note this EIAS principle is only true at a conceptual level, and for reasons of efficiency the implementation may choose different internal representations for a value depending on its usage. For example, arithmetic operations on integers may internally store the value as a native machine word. Similarly, a binary string is a sequence of Unicode code points in the range U+0000 to U+00FF and may be stored as an array of bytes. In all cases this internal representation is irrelevant at the Tcl language level but exposed in the Tcl C API. πŸ’€

πŸ”‘ KEYWORDS πŸ”‘

  • backslash
  • command
  • comment
  • script
  • substitution
  • variable

Okay that's the whole page, bestie β€” and ily for making it to the very end. 🌸 This one's the Tcl 8.6 version, coming to you from the Tcl(3tcl) manual page, so if your version differs, that's between you and your distro. Go forth and subst responsibly πŸ‘‘βœ¨πŸ’–

πŸ“¦ where this page comes from
  • ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms