7 lines of code, 3 minutes: Implement a programming language (2010)

· coding · Source ↗

TLDR

  • A 7-line Scheme interpreter for the lambda calculus teaches eval/apply architecture and scales to a 100-line subset-of-Scheme interpreter in one afternoon.

Key Takeaways

  • The lambda calculus has only three expression types: variable references, anonymous functions, and function calls, yet is Turing-equivalent via Church encodings and the Y combinator.
  • The core eval/apply pattern from SICP drives both the minimal interpreter and the larger 100-line Racket version with let, letrec, set!, begin, and primitives.
  • Scheme’s read handles lexing and parsing automatically for s-expression syntax, letting you focus on semantics from the start.
  • The 100-line interpreter uses mutable hash-based environments and transforms top-level define forms into a single letrec before evaluation.
  • Separating syntactic design from semantic design is practical: build a parser that emits s-expressions, then feed it to the eval/apply core.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN