tlliContext* ctx;
tlliEvaluate(ctx, "(if (<= 1 2) (print \"success\") (print \"fail\"))", NULL);

I love programming languages. Occasionally I just go and look at some, see how they differ from what I’ve already used, sometimes I try and use them. I occasionally develop a fondness for particular ones. I’ve experimented with interpreted languages, compiled languages, symbol based languages, image based languages. One family of languages I have repeatedly dabbled with but not yet found any actual projects to do anything with, is functional languages. I have dabbled a little with elisp to set up emacs, and I’ve tinkered with haskell when configuring xmonad, but I have yet to find something I want to make for myself in one of these languages.

So, why not do the next best thing and try to create one. I had read that implementing a lisp is relatively straightforward, so why not do so?

My lisp is based around¬†tlliParseFunc. The standard method of creating a lisp is to write an evaluate function and let everything grow from there. In my case though the evaluate just tokenises the string given and passes it on to the parse. I could probably do with renaming things, but that’s how it works. I have a few keywords and symbols, which I couldn’t figure out how to do otherwise. They are: ‘(‘, which passes the current scope to another parse call, ‘)’ which completes the function call, ‘defun’ to define a new function and ‘if’. Everything else is then available to use as a symbol name. As there is nothing I could do with the language without some very basic building blocks, I’ve also had to define a number of native functions with which I could then use for further¬†functions which could be defined in lisp itself. This means that you should be able to do something like this:

tlli> (- 1 2)
tlli> (defun - (a b) (+ a b))
tlli> (- 1 2)

Unfortunately, I am currently using a very simple map implementation I wrote just to test the concept and it doesn’t check for clashes, so the defun is adding a ‘new’ value to the end of the map, rather than replacing the existing function. Obviously this needs to be fixed…Fixed. You can now redefine things as much as you want.

Leave a Reply

Your email address will not be published. Required fields are marked *

Diary of a Slacker