Hello, I'm Nick Fitzgerald. This is my weblog. You can also check out my shared items from Reader and code on GitHub. Feel free to contact me about whatever.
June 25th, 2010
I couldn't help it.
Between my current PL course and reading Lisp in Small Pieces off-and-on, I had to start writing my own Lisp again. I have named it Magritte, after René Magritte. So far just the basics are working. Pattern matching and destructuring, but no guards yet. Lambdas are a go, but the lexical scope is a little buggy still. No macros yet.
Here is the famed Y Combinator, in Magritte.
magritte> (defn (Y X)
((fn (procedure)
(X (fn (arg) ((procedure procedure) arg))))
(fn (procedure)
(X (fn (arg) ((procedure procedure) arg))))))
(((X) . #<CLOSURE # {BD7D315}>))
magritte> (def fact (Y (fn (f) (fn (n)
(if (eq? n 0)
1
(* n (f (- n 1))))))))
#<CLOSURE (LAMBDA (VALUES &KEY (BINDINGS NIL))) {BA383E5}>
magritte> (fact 3)
6
magritte> (fact 8)
40320
And here is a pretty typical definition of map, using pattern matching and destructuring.
magritte> (defn (map f ()) ())
(((F NIL) . #<CLOSURE # {B83C1D5}>))
magritte> (defn (map f (h . t)) (cons (f h) (map f t)))
(((F (H . T)) . #<CLOSURE # {BB4C0E5}>)
((F NIL) . #<CLOSURE # {B83C1D5}>))
magritte> (map (fn (x) (* x x)) '(1 2 3 4 5 6 7 8 9))
(1 4 9 16 25 36 49 64 81)
Currently, Magritte is written in Common Lisp. My plan is to get the interpreter to a decent level of quality, then write a Magritte -> Common Lisp compiler, in Magritte. Then we'll really be having some fun!
On August 10th, 2010
On August 2nd, 2010
On July 23rd, 2010
On July 19th, 2010
On July 5th, 2010
On June 29th, 2010
On June 25th, 2010
On June 21st, 2010
On June 2nd, 2010
On May 20th, 2010
blog comments powered by Disqus