

Real world examples using homoiconicity? - jasonwatkinspdx

I'm interested in example code that uses homoiconicity well. I'm not interested in pedagogical examples, such as the excellent and oft cited meta-circular evaluator.<p>I'd also be interested to hear the opinions of lisp users and the like on the benefits of homoiconic code vs the risks of using eval() or the equivalent.
======
pavelludiq
I only know lisp, so I'll use it as an example, but there are other homoiconic
languages out there.

In lisp i can do this:

    
    
      (eval (cons '+ '(1 2 3)))
    

What i did was that i added the symbol + to the front of the list (1 2 3) to
get (+ 1 2 3) which is a valid lisp expression, and i eval-ed it resulting in
6.

i can do other such things:

    
    
      (eval (reverse '(3 2 1 +)))
    

I take the list (3 2 1 +) which is an invalid lisp expression, and i reverse
it, giving me (+ 1 2 3).

See what we did here? We took a datastructure and we transformed it into
something the lisp compiler can recognize as a valid form. We can do this
because lisp code is expressed as lisp datastructures(thats what homoiconic
means).

~~~
jasonwatkinspdx
These are great teaching examples, but what I haven't seen yet is how it can
be used solving problems or implementing algorithms. I'm very curious what
such code looks like and how homoiconicity is leveraged to advantage.

~~~
pavelludiq
Ok then, check out this awesome DSL example screencast in common lisp:
<http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1>

I don't know how much common lisp you know, but you asked for a real example.

Also check out this awesome talk by Shriram Krishnamurthi:
[http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePe...](http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePerl/)
(audio and slides). It uses scheme. There are many more examples, but these
are just off the top of my head.

~~~
jasonwatkinspdx
Thanks, I'll check these out.

