Skip to content

About

scheme interpreter and python implement

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

I take the course from https://www.dabeaz.com/sicp.html.
The course go through the sicp book.
I only put my implemention in this repo.
If you are going to take the course. You may want to check it.

Files

util.py shared tokenizer/reader (incl. ' quote sugar) + builtin table scheme_env.py environment-model interpreter (SICP ch.3 style) scheme_subtitue.py substitution-model interpreter (SICP ch.1 style) meta.ss racket meta-circular interpreter (runs only under racket) diff_all.py unified differential harness tests/ corpus, runnable under both python interpreters advance_tests/ harder corpus, also runnable under both python interpreters

Run

python3 diff_all.py

diff_all.py runs every .ss under tests/ and advance_tests/ through both python interpreters (env model + substitution model), compares their final values, and cross-checks against racket whenever a racket binary is on PATH (auto-detected; otherwise the oracle column reports SKIPPED). Known divergences live in docs/goal/divergence-baseline.json; the run exits 1 on any failure outside the baseline, on a stale baseline entry whose file now passes, or on a ghost entry whose file disappeared.

Run one file with a single interpreter:

python3 scheme_env.py file.ss
python3 scheme_subtitue.py file.ss

Interpreter design

Both python interpreters are explicit-continuation-frame (CEK-style) machines: the continuation is data (a tuple of frames), driven by a trampoline (constant Python stack, so Scheme recursion depth is unbounded). They cover: define, set!, if (incl. one-armed), cond, begin, let, let*, letrec, lambda with multi-expression bodies, and/or (short-circuit), quote with the ' reader sugar, call/cc (call-with-current-continuation, aborting), and the delimited forms call-with-continuation-prompt and call-with-composable-continuation (composable continuations, matching racket's guide 10.3).

Racket

Install via Homebrew (or the official installer from download.racket-lang.org):

brew install racket

diff_all.py detects racket on PATH automatically; no further setup needed.

Known limitations

  • One-armed if is a deliberate local extension; racket requires a 3-arg if with an else branch (recorded in the divergence baseline).
  • The substitution model (SICP ch.1 style) cannot mutate inside lambda bodies — set! works at top level only.

About

scheme interpreter and python implement

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages