Language
Tcl
- First appeared
- 1988
- Paradigm
- Imperative, scripting, command-based
- Toolchain
- Tcl 9.0.1
- Container image
debian:trixie-20261027-slim + tcl9.0 9.0.1+dfsg-2
Tcl (Tool Command Language, often said “tickle”) was created by John Ousterhout at UC Berkeley in 1988 as a small language to embed in other programs. With its Tk toolkit it became a quick way to build desktop interfaces, and it still runs inside chip-design tools, network test equipment, and Expect, the classic tool for scripting interactive programs.
Tcl has almost no syntax. Every line is a command followed by its
arguments, and every value is a string. $name substitutes a variable,
[command] runs a command and substitutes its result, and {braces} quote
text without substituting anything. Even if and while are ordinary
commands that take their bodies as braced strings. Arithmetic happens only
inside expr. Lists and dictionaries are built in; Tcllib, the large
add-on library with statistics and matrix packages, isn’t installed here.
Quirks
lsortcompares text unless told otherwise, solsort {3.5 1.25 2 10}gives1.25 10 2 3.5.lsort -realsorts them as numbers.- Brace your expressions. With
set x "1 + 2",expr $xgives 3, because Tcl substitutes$xfirst andexprthen reads the text as code.expr {$x}gives back the string1 + 2. 7 / 2is 3, and-7 / 2is −4: integer division rounds down, not toward zero.7 / 2.0is 3.5.foreach x {1 2 3} y {a b}walks both lists in step, and when one runs out, it pads with empty strings instead of stopping: the last pass getsx= 3 and an emptyy.- Integers never overflow:
2**70is 1180591620717411303424. ==compares numbers when it can:"10" == "10.0"is true, whilestring equal 10 10.0is false.
Concepts in Tcl
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Tcl example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language tcl