A Lisp in 99LOC

https://news.ycombinator.com/rss Hits: 16
Summary

Lisp in 99 lines of C and how to write one yourself In honor of the contributions made by Church and McCarthy, I wrote this project and the accompanying article to show how anyone can write a tiny Lisp interpreter in a few lines of C or in any "C-like" programming language for that matter. I attempted to preserve the original meaning and flavor of Lisp as much as possible. As a result, the C code in this project is strongly Lisp-like in compact form. Despite being small, these tiny Lisp interpreters in C include 21 built-in Lisp primitives, simple garbage collection and REPL, which makes them a bit more practical than a toy example. If desired, more Lisp features can be easily added with a few more lines of C as explained in my article with examples that are ready for you to try. Tinylisp running on a vintage Sharp PC-G850VS pocket computer A cool pocket computer with a built-in C compiler. Tinylisp compiles and runs on this machine too with its native C! How is tinylisp so small? Using NaN boxing (or BCD boxing) and some programming tricks in C. See my article for details, examples and detailed instructions how to extend tinylisp with more features. Project code Lisp in 99 lines is written in a Lisp-like functional style of structured C, lines are 55 columns wide on average and never wider than 120 columns for convenient editing. It supports static scoping, double precision floating point, has 21 built-in Lisp primitives, a REPL and a simple garbage collector. Tail-call optimized versions are included for speed and reduced memory use. tinylisp.c Lisp in 99 lines of C with double precision tinylisp-commented.c commented version in an (overly) verbose C style tinylisp-opt.c optimized version for speed and reduced memory use tinylisp-float.c Lisp in 99 lines of C with single precision tinylisp-float-opt.c optimized version with single precision lisp850.c Lisp in 99 lines of C for the Sharp PC-G850 with BCD boxing lisp850-opt.c optimized version for speed and reduced m...

First seen: 2025-08-16 22:31

Last seen: 2025-08-17 13:34