Skip to content
jacktrades edited this page Nov 23, 2011 · 2 revisions

Scheme in Python is a simple Scheme interpreter written in Python.

This was created for a tutorial on the incremental development of an interpreter. The tutorial series was based on an earlier version of this code and can be found at: http://nickzarr.com/blog4/series/scheme-in-python/ However this code has underwent some serious refactoring and the entire series is scheduled for a complete rewrite.

This interpreter is developed around my interpretation of the "languages as libraries" concept (like Racket or PyPy). The implementation has been kept as simple as possible to make this accessible for the novice programming language researcher.

Scheme in Python does not attempt, in any way, to make a complete implementation of the Scheme programming language. There is no effort to make it either robust or efficient. The entire purpose of this implementation is to provide a step-by-step guide to the fundamentals of implementing a programming language.

With that out of the way, here's an example session:

/code/Scheme in Python$ python scheme.py
> 42
42
> -.42
-0.42
> 4/2
rationals not implemented
> #t
True
> #f
False
> #\a
a
> #\space

> hello
Error: Unbound symbol: hello
> (define hello "world")

> hello
world
> (if #t 1 0)
1
> (if #f 1 0)
0
> (+ 3 4)
7
> ((fn (x) x) 42)
42
> (define echo (fn (x) x))

> (echo 42)
42
> (define add (fn (x y) (+ x y)))

> (add 3 4)
7

The entire project is comprised of 260 lines of code, not including whitespace, comments and tests. The code was written so that novice programmers could understand it.

There will be some additional development on this codebase, however this project is near completion (with the exception of the tutorial series). There will be no attempt at implementing a large subset of the Scheme standard. This is by design, as it will allow the reader to experiment with implementation of language features on their own.

(c)2011 Nick Zarczynski

Clone this wiki locally