Making a Lisp in Python

The Make a Lisp repository on GitHub looks like a great resource for a guide on implementing your own lisp interpreter which, for reasonsTM I’m growing increasingly interested in.

Sure, Python might not be the best language for this, but it’s the one I’m fluent in which is good enough for now as I’m only looking to get a feel for the ideas.

Setup

To get setup I had to

  1. Clone the mal repo:

    ~/Projects $ mkdir -p kanaka/mal
    ~/Projects $ git clone https://github.com/kanaka/mal kanaka/mal/master
    
  2. Create a folder for my implementation

    mal/master $ mkdir impls/py

  3. Make the edits described in the Getting Started guide to Makefile.impls

    IMPLS = ... py ...
    ...
    py_STEP_TO_PROG = impls/py/$($(1)).py
    
  4. Add the run file:

    mal-py run
    #!/usr/bin/env bash
    exec python $(dirname $0)/${STEP:-stepA_mal}.py "${@}"
    
  5. Then because I’m embedding the source for my implementation in this site using awdur, I added the following to my Makefile, automating the extraction of the code and execution of the tests for the current step.

    mal: dotfiles
        -rm $(PROJECTS)/kanaka/mal/master/impls/py/*
        cp $(DOTFILES)/mal-py/* $(PROJECTS)/kanaka/mal/master/impls/py/
        make -C $(PROJECTS)/kanaka/mal/master/ test^py^stepN