Skip to content

Instantly share code, notes, and snippets.

@john-science
Last active December 9, 2021 05:27
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save john-science/6701bbbf558c61d17d41 to your computer and use it in GitHub Desktop.
Save john-science/6701bbbf558c61d17d41 to your computer and use it in GitHub Desktop.
Build Your Own LISP

Build Your Own LISP

I had fun building my own LISP (Slow Loris). The project was extremely easy to get off the ground, because there a ton of resources to do just this. I thought it might be handy to have a little links round-up, based on my research.

In Python

There are already several good projects out there on writing your own LISP in Python.

Peter Norvig's LisPy

This is a seminal work, that is much referenced. Norvig starts out describing everything that's being built in clear, simple terms, and builds up from the foundation. Lots of working code and examples.

LISP as the Maxwell's Equations of Software

This is an even older and more respectable piece on the topic. This was a bit more theoretical, but still very useful.

Assorted GitHub

And, of course, there are some assorted GitHub projects that build their own LISP in Python.

In C

If you want your LISP to be fast and popular, you probably need to write it in a more low-level language. C is a good option. There is a whole book on this:

Python in C

If you want a nice (albeit VERY extensive) reference for writing a language in C, the Python language is written in C and the source code is available online:

Importing Python from C

You can also, of course, import Python code from C:

Compile Python

Or maybe you just want to compile your Python-based LISP down using Cython.

Other Options

The benefit of writing your LISP in C is that you will, theoretically, end up with a faster language. But there are perhaps other benefits that might be more important to you. Portability comes to mind. For your LISP to be truly portable, it would be nice if it ran on a common virtual machine. In that case, perhaps your LISP should be written directly for the Java or Python virtual machine. There is a nice introduction to Python bytecode here:

However, the structure of Python bytecode changes regularly, even in minor language versions. So it would probably be smarter to write for the Java Virtual Machine (JVM), which is less of a moving target. To write a language for the JVM, you will want to reference the Java Specification guide:

There is also a nice StackOverflow answer with a lot of references on writing for the JVM here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment