Martin Karlsson /

Notes to self

Make A Lisp (step 0)

Make A lisp (MAL) is a project by Joel Martin that implements a minimal Clojure-like lisp interpreter in 80+ languages. Clojure-like in the sense that there is dedicated notation for arrays ([square brackets]) that would just be quoted lists in traditional lisps. There is also no CAR or CDR for list access, instead we get "first" and "rest" functions. Of course, Clojure's claim to fame is "getting concurrency right" and there is none of that here. I'm not a lisp programmer (Clojure or traditional) so there might be more things.

MAL as a language is pretty useless because of the lack of libraries (or even, as far as I can tell, a way to make and include libraries). Instead it's a learning tool. As a person who has been aware of lisp for decades now without ever actually mustering up the will to learn any lisp this is pretty compelling. The real usefulness of the MAL project is the tests. Joel has written hundreds of implementation independent black box tests and a nice 10 step guide on how to implement a MAL.

So I decided to try it. This is the write-up of doing step 0.

The first thing to do is to choose an implementation language. My go-to language for getting stuff done has been Python for many years. I program C# for a living and I spend my work days inside of Visual Studio and the Azure portal. By the nature of the programs I've been working on (paid for and for fun) I've seen and written plenty of SQL. I can do Powershell and Bash when circumstances require it. I'm a decent C programmer in the embedded space. So I chose PHP.

I'm not a complete beginner when it comes to PHP. My first web programming was PHP. This was in 2005. The language (or at least, what I got to see of it) was small. There where some frameworks around but I didn't know about them and didn't use them. It was easy to deploy (still is, it seems). So I have somewhat fond memories of PHP. Except the dollar sign variables, fuck those. For what I did with it, template based web pages and basic auth for admin users, it worked well. I was pretty clueless about good code organization (architecture if you are feeling fancy), at least more so than now, so my projects was a bit messy. But that's not really on PHP. Eventually I got out of web programming (I was never really "in") and dropped PHP. I thought it might be fun to revisit.

Step 0 of the MAL implementation is to write the stub of a REPL loop. The only functionality required is a loop in main that displays a prompt "user> " (final space is required to get the tests to pass). Any text entered on the prompt is then written back to the terminal. The guide recommends splitting this into READ, EVAL and PRINT functions and a final rep function that calls these in order, passing the string entered by the user from one to the next. The guide also tells you to place the code under a folder named after your language, PHP in my case. The guide does not explicitly state this but that folder must in turn be placed under the "impl/" folder of the MAL project for the test to find it. The "impl/" folder already has a "php/" folder so I named mine "php2/". The guide then has you edit the make file that runs the tests, so that the implementation is found. That's it for step 0!

Get in touch: martin [at]