I am implementing a Lisp interpreter in pure C and am having trouble transitioning from C into Lisp.
Following Peter Norvig's steps in his blog post, I have a REPL which so far parses Lisp expressions into Lisp data structures and serializes the resulting data structure back into a lisp expression that is printed as shown below:
I also have implemented the seven primitives described by Paul Grahm, and understand the metacircular evaluator therein. My troubles arise in writing the part of the C code (not lisp!) that actually executes the data structure once it has been parsed (the "eval") part in the image shown above.
From my understanding, with the metacircular evaluator it is possible to write the semantics of evaluating Lisp procedures in Lisp itself. Because of this I want to leave this part of the program in lisp, however, it seems apparent that at some point I need to write C code that actually applies primitives or procedures to Lisp data structures. When I go to write this code however, I find myself writing the same logic as the metacircular evaluator itslef, just the C version.
My question is whether I need to implement eval
and apply
in C (as Peter Norvig did in Python) or whether there is some way to bootstrap the lisp interpreter where the only implementation of eval
and apply
are actually written in Lisp?