Est. 1988 Beginner

Tcl

The embeddable scripting language that powered early internet applications - simple, extensible, and still running critical systems worldwide.

Created by John Ousterhout (UC Berkeley)

Paradigm Multi-paradigm: Event-driven, Procedural, Functional
Typing Dynamic, Weak
First Appeared 1988
Latest Version Tcl 9.0 (2024)

Tcl (Tool Command Language, pronounced “tickle”) is a dynamic scripting language created by John Ousterhout in 1988 at the University of California, Berkeley. Originally designed as an embeddable command language for applications, Tcl became one of the most influential scripting languages, particularly known for its simplicity, extensibility, and the Tk graphical toolkit.

History & Origins

John Ousterhout developed Tcl while working on CAD (Computer-Aided Design) tools at UC Berkeley. He observed that many tools needed a command language but were wasting effort implementing incompatible ones. His solution was to create a reusable, embeddable language that any application could adopt.

The Design Philosophy

Ousterhout articulated several key principles:

  1. Everything is a string - All values, including code, are represented as strings
  2. Everything is a command - Every operation is a command with arguments
  3. Minimal syntax - Just 12 rules define the entire language
  4. Embeddable - Designed to be embedded in C applications
  5. Extensible - Easy to add new commands in C or Tcl

The Name

“Tcl” stands for Tool Command Language. It was designed to be the command language that tools would embed, eliminating the need for each tool to invent its own scripting language.

Why Tcl Was Revolutionary

In the late 1980s, most applications had no scripting capability. Tcl changed this:

1. Radical Simplicity

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Print hello world
puts "Hello, World!"

# Variables
set name "Tcl"
puts "Hello from $name!"

# Commands and expressions
set sum [expr {2 + 2}]
puts "2 + 2 = $sum"

The entire language syntax fits on a single page.

2. Everything is a String

In Tcl, all data is represented as strings. Even code is just strings that can be manipulated and executed:

1
2
set code {puts "Dynamic code!"}
eval $code

3. Easy Embedding

Tcl was designed from day one to be embedded in C applications:

1
2
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_Eval(interp, "puts {Hello from C}");

4. Tk - GUI Made Simple

The Tk toolkit made creating graphical interfaces trivially easy:

1
2
3
package require Tk
button .b -text "Click me!" -command {puts "Clicked!"}
pack .b

Tcl Implementations

Tcl has several implementations:

ImplementationPlatformNotes
Tcl/TkAll platformsThe official implementation
JTclJVMTcl interpreter in Java
AndroWishAndroidTcl/Tk for Android devices
JaclJVMOlder Java implementation
Jim TclEmbeddedLightweight for embedded systems
Tcl.jsBrowserTcl in JavaScript

For this tutorial series, we’ll use the official Tcl interpreter (tclsh).

The Tcl Structure

Tcl programs have an incredibly simple structure:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Variables
set greeting "Hello"
set name "World"

# String substitution
puts "$greeting, $name!"

# Procedures
proc add {a b} {
    return [expr {$a + $b}]
}
puts [add 2 3]

# Conditionals
if {$name eq "World"} {
    puts "Global greeting!"
} else {
    puts "Personal greeting!"
}

# Loops
for {set i 1} {$i <= 5} {incr i} {
    puts "Count: $i"
}

Key Language Features

  • Commands - Everything is a command: command arg1 arg2 ...
  • Substitution - $var for variables, [cmd] for command results
  • Quoting - {braces} prevent substitution, "quotes" allow it
  • Lists - Natural list handling: {a b c d}
  • Dictionaries - Key-value pairs: dict create key value

The Tcl Community

Tcl maintains an active community:

  • Tcl’ers Wiki - wiki.tcl-lang.org with extensive documentation
  • Tcl Developer Xchange - www.tcl.tk main community site
  • comp.lang.tcl - Long-running Usenet newsgroup
  • Tcl Conference - Annual conference since 1993
  • ActiveTcl - Commercial distribution by ActiveState

Tcl in Modern Context

While Tcl’s peak popularity was in the 1990s-2000s, it remains relevant:

Still Running

  • Network equipment - Cisco IOS, Juniper, and others embed Tcl
  • EDA tools - Chip design software relies heavily on Tcl scripting
  • Test automation - Expect and DejaGnu power critical testing infrastructure
  • Scientific software - VMD, NAMD, and other tools use Tcl

Modern Use Cases

  • Embedded scripting - IoT devices and appliances
  • DevOps automation - Expect scripts for SSH/Telnet automation
  • GUI prototyping - Tk remains useful for quick GUI tools
  • Testing - SQLite’s test suite demonstrates Tcl’s utility

Getting Started

Tcl files typically use these extensions:

  • .tcl - Standard extension
  • .tk - Tk GUI applications
  • .tbc - Tcl bytecode (compiled)

A typical Tcl development workflow:

1
2
3
4
5
6
7
# Write your program
cat > hello.tcl << 'EOF'
puts "Hello, World!"
EOF

# Run with tclsh
tclsh hello.tcl

Continue to the Hello World tutorial to write your first Tcl program.

Timeline

1988
John Ousterhout creates Tcl at UC Berkeley as an embeddable command language
1990
Tk graphical toolkit released, creating the Tcl/Tk combination
1994
Tcl becomes one of the first web scripting languages; used in early CGI applications
1997
Tcl 8.0 released with bytecode compiler, dramatically improving performance
1998
Sun Microsystems acquires Tcl development; John Ousterhout joins Sun
2000
Tcl Developer Xchange (tcl.tk) established as community hub
2007
Tcl 8.5 released with major improvements to expr, dictionaries added
2012
Tcl 8.6 introduces coroutines and built-in object system (TclOO)
2016
Tcl/Tk moves to fossil version control; community-driven development continues
2024
Tcl 9.0 released, first major version in over a decade with UTF-8 internal encoding

Notable Uses & Legacy

Cisco IOS & Network Equipment

Cisco and many network equipment vendors use Tcl for embedded scripting and automation in routers and switches.

Expect (Automation Tool)

The famous Expect tool for automating interactive applications is built on Tcl, still widely used in DevOps.

EDA Tools (Electronic Design Automation)

Major chip design tools from Synopsys, Cadence, and Mentor Graphics use Tcl for scripting and customization.

OpenSees (Earthquake Simulation)

The Open System for Earthquake Engineering Simulation uses Tcl for model definition and analysis control.

SQLite Testing

SQLite's extensive test suite is written primarily in Tcl, helping ensure database reliability.

NAMD (Molecular Dynamics)

NAMD, a parallel molecular dynamics simulation tool, uses Tcl for scripting molecular simulations.

Language Influence

Influenced By

Lisp C Unix shell Awk

Influenced

Python Ruby PowerShell PHP

Running Today

Run examples using the official Docker image:

docker pull tclsh:9.0

Example usage:

docker run --rm -v $(pwd):/app -w /app tclsh:9.0 tclsh /app/hello.tcl

Topics Covered

Last updated: