

30 minutes Lisp in Ruby (direct link) - RyanMcGreal
http://gist.github.com/562017

======
akkartik
I wish somebody would build a toy lisp with some sort of macro. That's the
part of the implementation that is still opaque to me.

Last time this came up: <http://news.ycombinator.com/item?id=1468345>

~~~
EdiX
I don't know what's the proper way of implementing macros but I can tell you
how I did it in my toy lisp implementation: I compiled defmacro as a normal
function but I also added it to a macro table, then in my compile-form
function I would use this table to decide if the form is

a) a special form b) a function call c) a macro

(a) and (b) are obvious, (c) means I would call the compiled macro "function"
on the rest of the form and the execute compile-form on the result.

It's unhygenic and there's probably some fatal flaw I didn't catch.

~~~
bitsai
Question about (a):

How do you handle special forms? I wrote a toy Lisp interpreter in Clojure,
but couldn't figure out how to implement ', which I assumed should be
implemented as a special form.

~~~
EdiX
I handled them by generating the assembly code to implement them and setting
up the symbol tables as required, I implemented ' as abecedarius said and then
quote was a special form that compiled into something that "returned" the
requested symbol object.

PS similar deal with ` it would be expanded into a bunch of normal forms by
the parser ("reader" in lisp-speak) and from there it's implemented with
macros and functions, I copied Guy Steele example implementation, you can find
it somewhere.

~~~
bitsai
Thanks for the tips. It's probably time for me to stop messing around and
start reading the Lambda Papers in earnest...

------
JoelMcCracken
Lisp's simplicity is one of its most interesting features. As far as I know,
Lisp is the only language that can achieve such great power while managing to
be so simple.

Lisp has staying power.

------
kingkilr
It's kind of cheating to not even include a lexer/parser.

~~~
Goladus
If your platform provides one, why bother?

~~~
shaunxcode
so that you can read lisp source instead of [:+, 6, 7]

However the parsing is probably the easiest part so punting makes sense as you
can get down to the stuff that matters and add that in later.

