(bernsteinbear.com) Writing a Lisp, Part 0: Fundamentals | Max Bernstein
ROAM_REFS: https://bernsteinbear.com/blog/lisp/00_fundamentals/
- Writing a Lisp, Part 0: Fundamentals
October 27, 2016
So you want to write a Lisp interpreter. I did too, and then I wanted to write about it, so here we are with this post series.
I initially wanted to write a Lisp interpreter as an exercise. I decided to write V1 in C (based on these two series of blog posts). After much pointer shenanigans and an unholy amount of curly braces later, it worked — but was significantly longer and harder to read than a Lisp interpreter should be. So I decided to write V2 in OCaml, a functional programming language descended from SML. The SML family of languages has some features like pattern matching and an extensive type system that make writing interpreters and compilers an absolute dream.
I'm going to walk through writing a fully-functional Lisp interpreter in OCaml. If you're following along with the OCaml, great. If you want to try and build it in SML or Haskell or whatever, it shouldn't be too hard to translate. If you want to follow along in C… well, good luck. It'll be a lot more code.
I'm going to build up the interpreter in stages, starting with symbols and other literals, then moving to simple math, then finally writing the features to support a metacircular evaluator (meaning that you can write another Lisp interpreter in the Lisp you just wrote!).
Links to:
- (www.lwh.jp) Building LISP
- (peter.michaux.ca) peter.michaux.ca - Scheme from Scratch - Introduction
- (troydm.github.io) Writing Micro Compiler in OCaml - Troydm's Blog
- (www2.cs.sfu.ca) LISP Tutorial 1: Basic LISP Programming
- (buildyourownlisp.com) Contents • Build Your Own Lisp
- (howtowriteaprogram.blogspot.com) How to Write a Program: Lisp interpreter in 90 lines of C++
- mal/process/guide.md at master · kanaka/mal (part of (github.com) kanaka/mal: mal - Make a Lisp)