Greg Hewgill (ghewgill) wrote,
Greg Hewgill
ghewgill

an embeddable s-expression language in python

A few weeks ago, I was working on some code that needed an HTML templating system (for substituting variables and content into an HTML page template). I know there are many existing choices out there, but I've never actually looked at them and anyway, I like to build stuff myself. My first rendition was a really awful simple substitution that had no options for looping or conditionals. It did the job I needed at the time so I left it.

Last week I needed to add looping to the template system, so I patched it to sort of understand arrays of data, which aren't quite loops but it worked for the moment. I can foresee needing to add conditionals which would make the code (not to mention the template language) even more crufty.

I decided that if I'm going to solve this problem, I should solve it the right way. I remembered reading somewhere that "S-expressions make better XML than XML", so I thought I'd see whether I can apply that in practice. S-expressions were introduced about 50 years ago for the Lisp programming language and haven't changed since. If I'm going to use S-expressions to represent HTML, then I might as well implement the Lisp (or a Lisp-like) programming language to work with them.

To make what could be a long story shorter, I've now got an implementation of a subset of Lisp written in Python. Somehow, I managed to get this implemented before I found PyScheme, pylisp, Psyche, lython, and A simple scheme interpreter. Clearly I wasn't the first to think of this.

My plan is to integrate this Lisp-ish subset closely with Python so I can call back and forth between them. I've taken some liberties, for example I haven't implemented Lisp lists as linked lists, but instead as Python lists. I might regret this choice but I think it will make common things easier. Fortunately, I've been using the excellent doctest module to build unit tests which will make it a whole lot easier to change things when I need to.

Oh yeah, I called this project "Psil", which might stand for Python S-expression Intermediate Language, or it might be Lisp spelled backwards.

I'm currently reading up on Scheme because it's a much smaller language than the full Common Lisp and is better suited for embedding into other systems. I think I'll probably switch to a Scheme-based dialect.
Tags: lisp, psil
Subscribe

  • some random interesting links

    Cow humour What does 200 calories look like? World gliding aerobatics champ [video] (part 1 is also very impressive) The Coming Software…

  • les quatre saisons

    I've been home sick for three days and I've pretty much exhausted all my usual forms of internet entertainment. I'm all caught up on the RSS feeds I…

  • soda-free

    Sugary drinks are piling on the pounds: A report says that a single can of soda per day can add up to 15 pounds per year. The math works out pretty…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments