UP | HOME

Summary: Advprog 2026-04-20 — Intro to Interpreters

Table of Contents

Key Claims

  • This class introduces the interpreter topic for the course, pointing to tolk and the final assignment.
  • Students are expected to study CLOS and the packages/systems aspects of CL as prerequisites.
  • The jotter for this class (20260420-jotter.org) contains a live-coded arithmetic interpreter progression.

Summary

The 2026-04-20 class is the first interpreter session of Advprog. The class outline lists:

  • Aspects of Lisp: Packages and Systems, CLOS
  • Tolk (repository link)
  • Ungraded assignment: Lisp packaging and pattern matching
  • Final assignment: Interpreters

The jotter (20260420-jotter.org) is the substantive content. It shows a progression of arithmetic interpreter implementations in Common Lisp:

Interpreter v1: cond with consp checks

(defun interpret (ast)
  (cond ((numberp ast) ast)
        ((and (consp ast) (eq '+ (first ast)))
         (+ (interpret (second ast))
            (interpret (third ast))))
        ((and (consp ast) (eq '* (first ast)))
         (* (interpret (second ast))
            (interpret (third ast))))
        (t (error "Unrecognised AST: ~a" ast))))

Interpreter v2: cond + case on operator

Separates the consp check from operator dispatch using case / ecase.

Interpreter v3: trivia:match with quasiquote patterns

(defun interpret (ast)
  (match ast
    ((type number) ast)
    (`(+ ,l ,r) (+ (interpret l) (interpret r)))
    (`(* ,l ,r) (* (interpret l) (interpret r)))
    (_ (error "Unrecognized AST: ~a" ast))))

Interpreter v4: trivia:ematch (exhaustive match)

Same as v3 but ematch signals a pattern-match error on unmatched input rather than requiring an explicit _ fallthrough.

The progression illustrates the move from verbose low-level dispatch to idiomatic pattern matching. The AST here is an s-expression (list / number), not yet a CLOS class hierarchy — that step is in tolk itself.

Notes

  • The jotter uses bind from metabang-bind and named-readtables with :fare-quasiquote for the quasiquote extension.
  • The interpreter in the jotter operates directly on s-expressions, not on parsed CLOS objects. This is a deliberate pedagogical simplification.

Related