Hello ![]()
Maybe some of you guys will be interested.
I wrote a small Lisp interpretter embedded in Ruby.
The emdedding is very tight - Lisp macros are Ruby Proc objects
and Lisp lists are Ruby Arrays (so actually cdr/cons copy).
It is somewhat more Scheme-ish (or even Goo-ish) than Common Lisp-ish,
but the macro system is more like Common Lispâs.
[obj method args] is a reader macro for (send obj 'method args),
which expands to obj.send(:method, *args).
Here are some examples:
; Fib function
(defun fib (n)
(if (<= n 1)
1
(+ (fib (- n 1)) (fib (- n 2)))
)
)
(print (map fib '(1 2 3 4 5)))
; A small HTTP server
(ruby-eval ârequire âwebrickââ) ; import module
(let HTTPServer (ruby-eval âWEBrick::HTTPServerâ)) ; bind class name
; Configure the server
(let config [Hash new])
[config set 'Port 1337]
; Tell the class to make us a server object
(let server (send HTTPServer 'new config))
; Tell server to call our Hello World handler
(send server 'mount_proc â/helloâ
(lambda (req res)
[res body= â
Hello, world!
â][res field_set âContent-Typeâ âtext/htmlâ]
)
)
; Tell the server to go !
(send server 'start)
Because it supports macros you can do things like:
(def-server-html-mount server â/helloâ
(html (body (h3 âMacros greet youâ)))
)
and thatâs pretty cool, because Ruby itself doesnât support macros
and now you can use macros almost in Ruby ![]()
The download: http://zabor.org/taw/rlisp/
Documentation is only on my blog for now:
*
taw's blog: RLisp - Lisp naturally embedded in Ruby
It uses Martin Traversoâs Ruby port of ANTLR 3 for parsing.
Well, thatâs pretty much all
If you have any questions about it,
just ask
(on the mailing list, by private mail, or on the blog)
If you have any questions about it, just ask