Skip to content
 

Toy Scheme interpreter in Lua

As part of my Lisp studies, I have implemented a toy Scheme interpreter in roughly 1000 lines of Lua. It is here. It supports tail-call optimisation, lexical scope for closures, and first-class continuations via call/cc.

I have departed from the traditional approach of implementing a Scheme interpreter in Scheme itself because I wanted to avoid possible confusions between the defined language and the defining language. This has made a lot of the concepts clearer. The evaluator is written in continuation-passing style, which is easily done in Lua because the latter has tail-call optimisations. This way it is easier to reify continuations to first-class values.

I have also added a few primitives to allow me to run some examples, as the factorial and fibonacci functions. More primitives can be easily added if desired.

4 Comments

  1. Mario says:

    Cool! Very nice and readable implementation!

  2. [...] public links >> lexicalscope Toy Scheme interpreter in Lua First saved by Spudgens | 2 days ago Data Directed Programming with CLOS First saved by [...]

  3. [...] my previous Scheme toy interpreter in Lua, I have already tried twice to write a simple Scheme compiler. I failed mostly because the [...]

  4. [...] my previous Scheme toy interpreter in Lua, I have already tried twice to write a simple Scheme compiler. I failed mostly because the [...]

Leave a Reply