[plt-scheme] Lispish system in Scheme

From: Anton van Straaten (anton at appsolutions.com)
Date: Thu Jun 22 14:09:08 EDT 2006

Ivanyi Peter wrote:
> (It used to be a teaching exercise in LISP, how to write
> LISP in LISP.
> I thought I could do something similar in Scheme.)

One of the classic examples of that teaching exercise is the 
metacircular evaluator in SICP:

http://mitpress.mit.edu/sicp/full-text/sicp/book/node76.html

It implements a Scheme-like language, but tweaking it to fit whatever 
definition you have in mind for "Lisp" shouldn't be difficult, as long 
as you're thinking in terms of "toy" implementations.

Of course, if you want something more serious, Matthias has already 
posted a link.  Also, if your goal is to integrate more closely into PLT 
somehow, then Matthias' link will be more useful.

BTW, in your original example, you're right, it looks as though the 
usual result of (current-eval) is an evaluation procedure which calls 
itself recursively, and doesn't use current-eval.

IOW, current-eval provides you with a way to replace the current 
evaluator, by overriding its top-level entry-point, but doesn't give you 
a way to extend or selectively override the built-in evaluator.

Unless there's some other PLT trick to let you do that, your obvious 
choices are either to write an interpreter along the lines of the SICP 
example above (and similar to your pseudocode), or use something like 
the approach Jos Koot suggested, where you write a module language and 
override internal PLT operations like #%top to change the behavior of 
things like variable access.

Anton


Posted on the users mailing list.