Skip to content

Build Your Own Lisp

“Build Your Own Lisp” is a book + companion code repo that walks a reader through implementing a Lisp interpreter in C in under 1000 lines, using the author’s own mpc parser-combinator library. The progression is similar in spirit to mal’s 11 steps but C-specific and tighter: the reader is learning C at the same time as building the language, so the book is also one of the most-recommended on-ramp C tutorials of the last decade. The end result is “Lispy” — a small Lisp dialect with numbers, symbols, S-expressions, Q-expressions (quoted lists), conditionals, lambdas, recursive definitions, and basic error handling.

For KN-86 the value is C-specific implementation reference for the embedded scripting layer — the same goal as mal, but with the substrate (C99, manual memory management, single-pass parser, recursive evaluator) that matches the existing kn86-emulator/ C11 codebase directly.

  • C in <1000 lines as the existence proof. Builds a working Lisp in C99 with no language runtime beyond libc and the mpc parser library. This is the right granularity for the fallback path in KN-86’s scripting-layer architecture: if Fe (ADR-0004) ever proves wrong-fit (memory model, GC behavior, FFI ergonomics) and the team needs to consider a from-scratch reimplementation, BuildYourOwnLisp is the closest single reference for what that would look like.
  • mpc parser-combinator library as a standalone takeaway. mpc is small, single-header-friendly, and well-tested. Independent of the embedded-Lisp decision, if KN-86 ever needs a parser for any structured text format (CIPHER fragments, mission-template DSLs, configuration files), mpc is worth reading for technique.
  • Q-expressions (quoted lists) as a structural decision. Lispy uses Q-expressions instead of standard quote for the data-vs-code distinction. KEC Lisp on KN-86 uses standard quote; the Lispy alternative is a useful read for understanding the trade-offs.
  • Pedagogy is similar to mal, but the audience is different. mal is for someone who already knows a programming language and wants to learn Lisp internals across many host languages. BuildYourOwnLisp is for someone who wants to learn C and Lisp at the same time. For KN-86 cart-authoring documentation, mal is the better structural reference for the “how to think about cart Lisp” docs; BuildYourOwnLisp is the better reference for the prose tone of an introductory cart-authoring tutorial — patient, concrete, explicit about what each new line of code does.
  • The book is not for vendoring or reproduction. The book text is CC-BY-NC-SA (non-commercial). KN-86 cart-authoring docs can cite BuildYourOwnLisp (“Daniel Holden’s Build Your Own Lisp is a more in-depth walkthrough of the implementation pattern…”) and link to the source, but must not reproduce passages from the book — write KN-86’s own prose in KN-86’s own voice.
  • mpc and the BYOL code are BSD-3-Clause — usable in KN-86 source if there’s ever a reason. (Right now there isn’t; Fe is the runtime.)
  • The book prose is CC-BY-NC-SA. Cite, link, do not reproduce.

No image downloaded.

  • Cross-link mal.md — the broader pedagogical reference and the language-agnostic version.
  • Cross-link cl-termbox2.md — the integration-side reference. mal + BYOL teach you how to build the Lisp; cl-termbox2 teaches you how to connect it to a screen.
  • Cross-link tuibox.md + termbox2.md — the C-core terminal stack that BYOL-style Lispy could drive end-to-end.