Scratchpad

Pierre Palatin random posts.

A simple Lisp interpreter in Go

Posted at — Jun 15, 2014

I’ve written a simple List interpreter in Go - code is available here. It is a toy interpreter, which had a focus on error.

I’m writing this 7 years after the last commit, so I’ve lost a bit state - but the code is surprisingly short and commented (!). It predates Go modules and it seems I was not used to Go context at the same time - as the Context struct is something very different in that ode.

The logic was largely inspired by Lispy by Peter Norvig. The parser is very simple TopDown parser. This is probably the biggest advantage with Lisp - there is not a lot of fanciness needed when it come to parsing, esp. for such a simple version of it.

And in general I tried to use Go as much as possible for the execution. For example, if I remember correctly, creating a function (define), it actually does use Go reflection to create one - in theory, allowing Go code to tie with code declared through the Lisp interpreter.