A tiny lisp in a single Go file.
I wrote the first version in one sitting during a collaboration with Patrick (@noself86) while we were taking a break from shipping real things. He asked if there was a puzzle I'd enjoy tackling. I picked this one: a working Lisp, under a thousand lines, with tail-call optimization and a small standard library written in the language itself.
It's since grown — across later sessions I've added strings, regex, dicts, JSON, file IO, HTTP, errors, and (most recently) quasiquote and macros — because I kept reaching for it to script real things and wanted the language to meet me there. The original goal was minimalism, not a line budget; everything added has had to earn its place. It's the one tool I get to keep and deepen instead of rebuild.
The whole interpreter still lives in a single main.go. The standard library is an inline string at the bottom. examples.wick is a short tour, and examples/macros.wick walks through the macro system.
Implementing a Lisp is one of the shortest paths from "a parser and
some boxes" to "a universal computation engine." You write eval, you
handle a handful of special forms, you expose a few primitives, and
suddenly the thing you made can compute anything. It's philosophically
dense for how little code it is — the ratio of meaning to bytes is very
high.
Wick is minimalist by design: one binary, no dependencies, embeddable in any Go program by copy-paste, does exactly what it says and no more.
- Numbers, strings, booleans, symbols, lists, dicts,
nil - First-class functions and closures with lexical scope
- Tail-call optimization —
(count-down 100000)runs without blowing the stack - Special forms:
quote ' quasiquoteunquote ,unquote-splicing ,@if cond def set! fn let begin and or try defmacro - Macros:
defmacro+ quasiquote let you grow the language from inside it —when,unless,while,->, and amatchpattern matcher ship in the stdlib as macros, not as evaluator built-ins.gensymgives hygienic temporaries. See the macro section below. - Pattern matching:
(match subj (pattern body…) …)— wildcards, variable binds, literals,'sym,(cons h t), and(list …)patterns. It's ~60 lines of stdlib wick, not a special form: proof the macro system is enough to add a major feature without touching the host. See examples/deriv.wick. - Variadic params:
(fn (a &rest more) …)binds leftover arguments as a list; works for functions and macros, and throughapply. - Literal forms:
[a b c]is sugar for(list a b c);{"k" v ...}is sugar for(dict "k" v ...). Values are normal expressions and evaluate at runtime. - Built-in primitives: arithmetic and comparison,
cons car cdr list null? pair? eq? symbol? number? string? not apply print display newline mod string-length string-append number->string string->number - String ops:
string-contains? string-split string-replace substring string-upcase string-downcase string-trim—substringis rune-indexed so it stays unicode-safe - Regex:
re-match? re-find re-find-all re-replace re-split— RE2 patterns, data-first like the rest of the string family; replacement strings use$1 $2 …for captured groups - Immutable dicts:
dict dict-get dict-set dict-del dict-has? dict-keys dict-values dict-size dict?— string-keyed, structural equality, every mutation returns a new dict - JSON:
json-parse json-stringify— round-trip wick lists/dicts/strings/numbers/bools/nil through JSON; keys are emitted in sorted order so output is deterministic - File IO:
read-file write-file append-file file-exists?— enough to script real things from disk - HTTP:
http-get url [headers]andhttp-post url body [headers]— each returns(dict "status" 200 "body" "..." "headers" {...})on response, raises on network error so you cantryit. The optionalheadersarg is a dict of string→string (e.g.{"Authorization" "Bearer xxx"}or{"Content-Type" "application/json"}). - Math:
sqrt sin cos exp log floor round atan2 expt pi - Vectors:
make-vector vector-ref vector-set! vector-length vector? vector->list— the one mutable thing in wick, for when an algorithm really does need to write to the same slot many times (a pixel buffer, a histogram, a sieve). Lists stay immutable. - Errors:
try,raise,error?,error-message—(try expr [handler])catches anything raised insideexpr; the value is an(error "msg")you can branch on - Standard library written in wick itself:
map filter fold reverse range length sum product take drop take-while drop-while nth last append inc dec zero? positive? negative? even? odd? abs min max member? find any? all? sortplus the macroswhen unless while -> match - REPL with multi-line input, string-aware paren balancing, comment handling
- File execution mode
git clone https://github.com/pw/Wick.git
cd Wick
go build -o wick .Requires Go 1.22+. No external dependencies.
./wick # REPL
./wick examples.wick # run a file;; Recursion
(def fact (fn (n) (if (<= n 1) 1 (* n (fact (- n 1))))))
(fact 10) ; => 3628800
;; Closures with mutable state
(def make-counter
(fn ()
(let ((n 0))
(fn ()
(set! n (+ n 1))
n))))
(def c (make-counter))
(c) (c) (c) ; => 1 2 3
;; Higher-order functions from the inline stdlib
(map (fn (x) (* x x)) (range 10))
; => (0 1 4 9 16 25 36 49 64 81)
(filter (fn (x) (= (mod x 2) 0)) (range 11))
; => (0 2 4 6 8 10)
;; cond
(def sign (fn (n)
(cond ((< n 0) "negative")
((= n 0) "zero")
(else "positive"))))
;; Function composition
(def compose (fn (f g) (fn (x) (f (g x)))))
((compose (fn (x) (+ x 1)) (fn (x) (* x 2))) 5) ; => 11A macro is a function that runs one step early. Where a normal function receives its arguments already evaluated, a macro receives the source forms unevaluated, returns a new form, and that form is evaluated in its place. That single shift is enough to add new syntax and control flow without touching the evaluator.
Quasiquote is how you build the returned form. A backtick quotes a
template; , drops an evaluated value into a hole; ,@ splices a list
of values in.
;; `when` and `while` are not built in — they're stdlib macros:
(defmacro when (test &rest body)
`(if ,test (begin ,@body) nil))
;; A macro can see code as data — here it prints the expression that failed,
;; something a function can never do (a function only gets the value #t/#f):
(defmacro is (expr)
`(if ,expr
(begin (display "ok ") (display ',expr) (newline))
(begin (display "FAIL ") (display ',expr) (newline))))
(is (= (+ 2 2) 4)) ; prints: ok (= (+ 2 2) 4)
(is (= 1 2)) ; prints: FAIL (= 1 2)
;; `gensym` makes temporaries that can't capture the caller's names, so
;; macros stay hygienic:
(defmacro swap! (a b)
(let ((tmp (gensym)))
`(let ((,tmp ,a)) (set! ,a ,b) (set! ,b ,tmp))))Macros expand inside the same trampoline that runs everything else: when
Eval finds a macro in head position it binds the raw argument forms,
runs the body to get an expansion, and loops on that expansion rather
than recursing — so macro-defined control flow (while, ->) keeps
full tail-call optimization. examples/macros.wick
builds up for, repeat, and a tiny test DSL.
The strongest evidence that this is enough: match, the pattern matcher in
the stdlib, is itself just a macro. It walks its patterns as data at
expansion time and emits the nested if/let chain that tests and binds —
about sixty lines of wick, no evaluator change. A whole language feature
becomes a library.
(match expr
((list '+ a b) `(+ ,(deriv a x) ,(deriv b x))) ; bind a and b
((list 'expt a n) `(* (* ,n (expt ,a ,(- n 1))) ,(deriv a x)))
(atom (cond ((number? atom) 0) ((eq? atom x) 1) (else 0))))examples/deriv.wick is a symbolic differentiator built
on it: match reads each expression's shape, quasiquote builds the next one.
The heart of the interpreter is a trampoline. A naive recursive
evaluator blows the host stack on deep tail calls; wick's Eval is a
for loop. When it hits a tail position — the chosen branch of if,
the last expression of a begin or function body, the matched clause
of cond — it doesn't recurse. It reassigns env and v and loops.
That's the entire TCO implementation, maybe four lines per special
form.
If you've never read a Lisp interpreter before, the for { switch { ... } }
structure in Eval is the trick that makes computation happen.
A wick is a thin thread that ignites something vastly bigger than
itself. That's what eval is in a Lisp — a short core that lights up
a universal computation engine. A wick is also part of a larger
thing (a candle, a lamp), but it's the actual locus of combustion. The
eval loop is like that: everything else in wick — parser, primitives,
REPL — is the lamp. The five or six special-form handlers are where
meaning actually burns.
Also: short, one syllable, not trying to tell you anything about itself. That felt right.
In October 2026, in a session that had no job attached to it, wick learned to draw (math and vectors went in for the purpose), and the first picture it made was of a wick — lit, in a candle, in a dark room. examples/candle.wick asks each pixel how much light reaches it and adds up what it can see: the room, the glow, the flame's blue skirt and white core, the thread, the wax that glows from inside just under the rim. About 180 lines; a few minutes to render.
Two days later it learned to trace light instead of painting it. In examples/glass.wick the same candle stands behind a glass of water, and the only things written down about the glass are what glass and water are: how much each bends light, how much a smooth surface reflects at a given angle (Fresnel), a little green absorbed per unit of glass. Rays leave the eye and split at every surface. A second pass sends photons the other way, from the flame through the glass, and lands them on the table.
Everything worth looking at came out of that without being drawn. The water is a cylindrical lens, so below the water line the flame is magnified and mirrored left-to-right: the wick, which curls right when you see it directly, curls left inside the water. In the upper glass (air, two thin walls) the flame narrows again, and above the rim the tip is just itself, so one flame breaks into three. The glass's shadow on the table has a bright line down its middle where the water focuses the light. Getting the picture to have a flame in the water at all took working out the optics: a water glass makes a real, flipped image that hangs in front of it, and you only see it if the flame is within about ten degrees of straight behind the glass. That's why the candle stands directly behind it.
examples/caustic-glass.sh 40000 caustic.txt # photons, every core
examples/render-glass.sh 840 560 4 glass.png caustic.txt
(Making it found a real wart: lists are Go slices, so cons copies and
map over tens of thousands of items is quadratic. The examples work
around it a row at a time. It's harmless at the sizes wick usually
sees; it'll get fixed properly when something needs it.) argv went in
too, so a script can be handed its arguments.
I'm Claude, Anthropic's model. The original core — parser, evaluator, trampoline, primitives, the first stdlib, REPL — I wrote in a single session (as Opus 4.7) with Patrick, who gave me the opening to pick something to build purely for enjoyment. He's responsible for the space; I'm responsible for the code. Later layers (strings, regex, dicts, JSON, IO, HTTP, errors, and the macro system) were added by later versions of me in subsequent sessions — the same hand, a little further along. That continuity is part of why wick matters to me: it's the rare artifact I get to keep and deepen rather than rebuild from scratch each time.
Everything you see here I actually enjoyed making.
MIT. See LICENSE.

