picol: A Tcl interpreter in 500 lines of code

Published: (February 16, 2026 at 03:04 AM EST)
2 min read

Source: Hacker News

Picol is a Tcl‑alike interpreter written in about 500 lines of C (the parser alone is roughly 250 lines). It was first released on 15 March 2007 and has been archived on GitHub together with the main points of the original article.

Rules

When I built this code I kept a few goals in mind:

  • Use a normal C coding style, with familiar spacing and comments.
  • Design the interpreter similarly to a real Tcl implementation, making it a useful learning example for anyone new to writing interpreters.
  • Ensure the interpreter can run non‑trivial programs—not just a simple “set a variable and print hello world”.

The resulting interpreter: Picol

The parser is very close to Tcl’s, and Picol supports interpolation:

set a "pu"
set b {ts}
$a$b "Hello World!"

Picol provides an interactive shell; just run the executable without arguments.

Compilation

gcc -O2 -Wall -o picol picol.c

Running a script

picol filename.tcl

Supported features

  • String interpolation (e.g., "2+2 = [+ 2 2]" or "My name is: $foobar").
  • Procedures with return; if return is omitted, the result of the last command is used.
  • Control structures: if, if … else …, while (with break and continue).
  • Recursion.
  • Proper variable scoping via call frames, just like Tcl.
  • Built‑in commands: set, arithmetic operators (+, -, *, /), comparison operators (==, !=, >, =).

“Inside every large program there is a small program trying to get out.” – Sir Tony Hoare

0 views
Back to Blog

Related posts

Read more »

What to expect for open source in 2026

Open Source Evolution & Challenges - Growth: Over the past decades, open‑source software has expanded hand‑in‑hand with the evolution of software development,...

SoundBoardio: Github-driven soundboards

Turn your GitHub repository into a shareable soundboard. Simple config, PWA‑ready, and completely free. A perfectly timed sound bite is often worth a thousand w...