Robert-van-Engelen/tinylisp
FreeLisp in 99 lines of C and how to write one yourself. Includes 21 Lisp primitives, garbage collection and REPL. Includes tail-call optimized versions for speed and reduced memory use.
FreeFree tier
About Robert-van-Engelen/tinylisp
tinylisp is a minimal Lisp interpreter written in 99 lines of C code, designed for educational purposes. It features 21 built-in Lisp primitives, a garbage collector, and a REPL. The project includes several optimized versions (tail-call optimization, single precision, BCD boxing for pocket computers) and an extended version with additional primitives for file loading, readline support, macros, and execution tracing. The code is strongly Lisp-like in style and demonstrates how to implement a tiny Lisp interpreter using NaN boxing techniques.
Key Features
99 lines of C implementation
21 built-in Lisp primitives
Garbage collection
REPL (Read-Eval-Print Loop)
Tail-call optimized versions for speed and reduced memory
NaN boxing for compact representation
Static scoping
Double precision floating point support
Multiple variants: optimized, single precision, pocket computer with BCD boxing
Extended version with 16 additional primitives (source loading, readline, exceptions, macros, backquoting, execution tracing)
Pros & Cons
Pros
- Extremely compact implementation (99 lines) makes it easy to understand
- Educational: includes commented version and accompanying article (tinylisp.pdf)
- Practical: includes essential features like GC, REPL, and tail-call optimization
- Multiple optimized versions for different use cases (speed, memory, single precision, BCD)
- Extensible: can add more Lisp features with few lines of C
Cons
- Limited to 21 primitives, not a full Lisp implementation
- Memory management is minimal (1024 cells by default, requires recompilation to increase)
- Primarily educational; may not be suitable for production use
- Documentation is mostly in the article PDF; may require additional reading material
Best For
Educational tool for learning how Lisp interpreters workEmbedding a lightweight Lisp in C applicationsRunning Lisp on resource-constrained embedded systems (e.g., Sharp PC-G850)Demonstrating how to implement programming languages
FAQ
How many lines of C is tinylisp?
tinylisp is implemented in 99 lines of C.
What primitives are included?
21 built-in Lisp primitives are included.
How do I compile tinylisp?
Use 'cc -o tinylisp tinylisp-opt.c' to compile.
Can I increase memory for tinylisp?
Yes, increase the value of N in the source code (default 1024 cells) and recompile.