About a year ago I read a programming post by Peter Norvig: (How to Write a (Lisp) Interpreter (in Python)), being a Python programmer, of course I had to try write my own Lisp interpreter as a way to learn lisp.
My implementation is relatively short, but can do some surprisingly complex things like this Y Combinatorial Factorial from wikipedia (which is one of my unittests):
I've recently dug up the files, rinsed them off, and put them on my bitbucket account. The reason I took another look at this project was my desire to translate it with Pypy. After having to battle just to get the tokeniser into valid RPython to translate I've put that on the backburner for now.
I learnt a surprising amount of functional programming "tricks" and techniques that apply equally to Python as to Lisp. As when I started learning Haskell, I grew more as a programmer and most importantly had fun!
Now I see Norvig has posted a follow up lispy2 so I'll have to read through it carefully to learn some more gems.
My implementation is relatively short, but can do some surprisingly complex things like this Y Combinatorial Factorial from wikipedia (which is one of my unittests):
(begin
(define Y
(lambda (f)
((lambda (x) (f (lambda (v) ((x x) v))))
(lambda (x) (f (lambda (v) ((x x) v)))))))
(define fact
(Y (lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1))))))))
(fact 10)
)
I've recently dug up the files, rinsed them off, and put them on my bitbucket account. The reason I took another look at this project was my desire to translate it with Pypy. After having to battle just to get the tokeniser into valid RPython to translate I've put that on the backburner for now.
I learnt a surprising amount of functional programming "tricks" and techniques that apply equally to Python as to Lisp. As when I started learning Haskell, I grew more as a programmer and most importantly had fun!
Now I see Norvig has posted a follow up lispy2 so I'll have to read through it carefully to learn some more gems.