I just wrote a Lisp interpretter embedded in Ruby. I used ANTLR 3.0ea7 for parsing (it's alpha-quality software, unfortunately).
$ cat examples/fib.rlThe dialect is supposed to be vaguely based on Scheme, but the idea was for it to be naturally embedded in Ruby, so many thing had to be changed compared to Scheme:
(defun fib (n)
(if (<= n 1)
(+ (fib (- n 1)) (fib (- n 2)))
(map fib '(1 2 3 4 5))
$ ./rlisp.rb <examples/fib.rl
(1 2 3 5 8)
- send function for method calls: (send 2 '+ 2) and syntactic sugar for it [obj method arguments], which evaluates to (obj 'method arguments). So it's possible to write [2 + [3 * 4]], what expands to (send 2 '+ (send 3 '* 4)). The syntax was stolen from Objective C.
- lists are implemented as arrays. So no cons, car or cdr. Now of course we need some replacement, and I haven't really thought about it. You can send get/set method to Array object, like that ('(a b c) set 0 'd) (or ['(a b c) get 0]).
- macro system - doh, that's the point of the whole thing
- links to Ruby object system, so we can define classes, methods etc.
- some support for iterators, I have no idea what syntax to select for iterators (send-with-iterator '(1 2 3) 'each (lambda (i) (print i))) would probably do the trick, but it's kinda uglyish.
- support for other basic Ruby objects like hash tables, regular expressions etc. Most of them need little more than (let a (send Hash 'new)), but some might not be very usable in such form.
- exception handling and callcc support would be cool
My box on which the code repository is located is behind a nasty nat, so just mail me if you want the code. :-)