# Lisp macros

**URL:** <https://rubytalk.org/t/lisp-macros/21128>\
**Category:** ruby-talk\
**Created:** [27 September 2005 01:25 UTC](https://rubytalk.org/t/lisp-macros/21128 "2005-09-27T01:25:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [27 September 2005 01:25 UTC](https://rubytalk.org/t/lisp-macros/21128/1 "2005-09-27T01:25:52Z")

</div>

Whoops, this belongs on ruby-talk... Sorry.

> **···**
>
> ---------- Forwarded message ----------  
> From: Joe Van Dyk \<[joevandyk@gmail.com](mailto:joevandyk@gmail.com)\>  
> Date: Sep 26, 2005 6:20 PM  
> Subject: Lisp macros  
> To: [rails@lists.rubyonrails.org](mailto:rails@lists.rubyonrails.org)
> 
> So, I'm diving into a little bit of Lisp, using  
> [http://www.gigamonkeys.com/book/](http://www.gigamonkeys.com/book/) as a starting point.
> 
> Lisp's big selling point is macros, right? I'm only up to chapter 3,  
> but from that (maybe very basic?) display of macros, it looks like  
> something that can be done in Ruby.
> 
> \<excerpt\>  
> (defun make-comparison-expr (field value)  
> &nbsp;&nbsp;`(equal (getf cd ,field) ,value))
> 
> (defun make-comparisons-list (fields)  
> &nbsp;&nbsp;(loop while fields  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collecting (make-comparison-expr (pop fields) (pop fields))))
> 
> (defmacro where (&rest clauses)  
> &nbsp;&nbsp;`#'(lambda (cd) (and ,@(make-comparisons-list clauses))))
> 
> CL-USER\> (macroexpand-1 '(where :title "Give Us a Break" :ripped t))  
> #'(LAMBDA (CD)  
> &nbsp;&nbsp;&nbsp;&nbsp;(AND (EQUAL (GETF CD :TITLE) "Give Us a Break")  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(EQUAL (GETF CD :RIPPED) T)))  
> T
> 
> You could use eval + procs to do that, right?
> 
> Joe

---

<div class="post-metadata">

**Author:** ![James\_Britt4](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@James\_Britt4](https://rubytalk.org/u/James_Britt4)\
**Post date:** [27 September 2005 01:46 UTC](https://rubytalk.org/t/lisp-macros/21128/2 "2005-09-27T01:46:41Z")

</div>

Joe Van Dyk wrote:

> Whoops, this belongs on ruby-talk... Sorry.

I trust the accidental exposure to Lisp wasn't too traumatizing.

Anyway, there have been sporadic discussions both here and on ruby-core about adding true Lisp-style macros to Ruby. My understanding is that while Ruby can do assorted flips and twists, it cannot do quite the same sort of things as found in Lisp (and I hope a true Lisper here can elaborate on this); I also believe that Matz is less than enamored with idea of adding this to Ruby (and I hope a true Matz can elaborate on this, too).

James

> **···**
>
> --
> 
> [http://www.ruby-doc.org](http://www.ruby-doc.org) - The Ruby Documentation Site  
> [http://www.rubyxml.com](http://www.rubyxml.com) - News, Articles, and Listings for Ruby & XML  
> [http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
> [http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![Devin\_Mullins](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Devin\_Mullins](https://rubytalk.org/u/Devin_Mullins)\
**Post date:** [27 September 2005 01:50 UTC](https://rubytalk.org/t/lisp-macros/21128/3 "2005-09-27T01:50:09Z")

</div>

The big thing Lisp has that Ruby can't do is code-as-data. I wish I could provide a good example of how that might be used practically, but it's been quite a while since I touched lisp.

Devin

Joe Van Dyk wrote:

> **···**
>
> > Whoops, this belongs on ruby-talk... Sorry.
> > 
> > ---------- Forwarded message ----------  
> > From: Joe Van Dyk \<joevandyk@gmail.com\>  
> > Date: Sep 26, 2005 6:20 PM  
> > Subject: Lisp macros  
> > To: rails@lists.rubyonrails.org
> > 
> > So, I'm diving into a little bit of Lisp, using  
> > [Practical Common Lisp](http://www.gigamonkeys.com/book/) as a starting point.
> > 
> > Lisp's big selling point is macros, right? I'm only up to chapter 3,  
> > but from that (maybe very basic?) display of macros, it looks like  
> > something that can be done in Ruby.
> > 
> > \<excerpt\>  
> > (defun make-comparison-expr (field value)  
> > `(equal (getf cd ,field) ,value))
> > 
> > (defun make-comparisons-list (fields)  
> > (loop while fields  
> > &nbsp;&nbsp;&nbsp;&nbsp;collecting (make-comparison-expr (pop fields) (pop fields))))
> > 
> > (defmacro where (&rest clauses)  
> > `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))
> > 
> > CL-USER\> (macroexpand-1 '(where :title "Give Us a Break" :ripped t))  
> > #'(LAMBDA (CD)  
> > &nbsp;&nbsp;&nbsp;(AND (EQUAL (GETF CD :TITLE) "Give Us a Break")  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(EQUAL (GETF CD :RIPPED) T)))  
> > T
> > 
> > You could use eval + procs to do that, right?
> > 
> > Joe

---

<div class="post-metadata">

**Author:** ![Lyndon\_Samson](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@Lyndon\_Samson](https://rubytalk.org/u/Lyndon_Samson)\
**Post date:** [27 September 2005 01:52 UTC](https://rubytalk.org/t/lisp-macros/21128/4 "2005-09-27T01:52:50Z")

</div>

Almost here with this [http://rubyforge.org/projects/parsetree/](http://rubyforge.org/projects/parsetree/) Just need to  
able able to modify it and feed it back.

This [http://boo.codehaus.org/Syntactic+Macros](http://boo.codehaus.org/Syntactic+Macros) is also interesting reading.

Lyndon

> **···**
>
> On 9/27/05, James Britt \<james\_b@neurogami.com\> wrote:
> 
> > Joe Van Dyk wrote:  
> > \> Whoops, this belongs on ruby-talk... Sorry.
> > 
> > I trust the accidental exposure to Lisp wasn't too traumatizing.
> > 
> > Anyway, there have been sporadic discussions both here and on ruby-core  
> > about adding true Lisp-style macros to Ruby. My understanding is that  
> > while Ruby can do assorted flips and twists, it cannot do quite the same  
> > sort of things as found in Lisp (and I hope a true Lisper here can  
> > elaborate on this); I also believe that Matz is less than enamored with  
> > idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> > this, too).

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [27 September 2005 01:53 UTC](https://rubytalk.org/t/lisp-macros/21128/5 "2005-09-27T01:53:02Z")

</div>

I'm just repeating what I've heard numerous times, but apparently, you  
can only get Lisp macros if the language has lots of silly irritating  
parenthesis. And since Ruby has syntax, it wouldn't be possible.

Or something. Don't pay attention to me. I have no clue what i'm  
talking about. ☹

> **···**
>
> On 9/26/05, James Britt \<james\_b@neurogami.com\> wrote:
> 
> > Joe Van Dyk wrote:  
> > \> Whoops, this belongs on ruby-talk... Sorry.
> > 
> > I trust the accidental exposure to Lisp wasn't too traumatizing.
> > 
> > Anyway, there have been sporadic discussions both here and on ruby-core  
> > about adding true Lisp-style macros to Ruby. My understanding is that  
> > while Ruby can do assorted flips and twists, it cannot do quite the same  
> > sort of things as found in Lisp (and I hope a true Lisper here can  
> > elaborate on this); I also believe that Matz is less than enamored with  
> > idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> > this, too).

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [27 September 2005 02:02 UTC](https://rubytalk.org/t/lisp-macros/21128/6 "2005-09-27T02:02:53Z")

</div>

If anyone wants to chime in with an example of what code-as-data is or  
how it could be used, I'd appreciate it!

> **···**
>
> On 9/26/05, Devin Mullins \<twifkak@comcast.net\> wrote:
> 
> > The big thing Lisp has that Ruby can't do is code-as-data. I wish I  
> > could provide a good example of how that might be used practically, but  
> > it's been quite a while since I touched lisp.

---

<div class="post-metadata">

**Author:** ![Michael\_Schuerig](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Michael\_Schuerig](https://rubytalk.org/u/Michael_Schuerig)\
**Post date:** [27 September 2005 02:21 UTC](https://rubytalk.org/t/lisp-macros/21128/7 "2005-09-27T02:21:42Z")

</div>

James Britt wrote:

> Joe Van Dyk wrote:
> 
> > Whoops, this belongs on ruby-talk... Sorry.
> 
> I trust the accidental exposure to Lisp wasn't too traumatizing.
> 
> Anyway, there have been sporadic discussions both here and on  
> ruby-core  
> about adding true Lisp-style macros to Ruby. My understanding is that  
> while Ruby can do assorted flips and twists, it cannot do quite the  
> same sort of things as found in Lisp (and I hope a true Lisper here  
> can elaborate on this); I also believe that Matz is less than enamored  
> with idea of adding this to Ruby (and I hope a true Matz can elaborate  
> on this, too).

I'm neither a true Matz nor a true Lisper. The basic facility Lisp  
macros offer over what is available in Ruby is that they do \*not\*  
evaluate their arguments. Where this is not an issue, you can get very  
far with what is there in Ruby.

Michael

> **···**
>
> --  
> Michael Schuerig The more it stays the same,  
> [mailto:michael@schuerig](mailto:michael@schuerig).de The less it changes!  
> [Michael Schürig | Sentenced to making sense](http://www.schuerig.de/michael/) --Spinal Tap, The Majesty of Rock

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [27 September 2005 05:01 UTC](https://rubytalk.org/t/lisp-macros/21128/8 "2005-09-27T05:01:00Z")

</div>

Matz has said (at the Lightweight Language Conf) that Ruby will never  
have macros because they are too easily abused, by the average person,  
to mutate the language.

Yes, Ruby has continuations and one can abuse them, but you have to  
be really smart. The average person won't even use them, let alone  
abuse them. 🙂

> **···**
>
> On 9/26/05, James Britt \<james\_b@neurogami.com\> wrote:
> 
> > Joe Van Dyk wrote:
> > 
> > Anyway, there have been sporadic discussions both here and on ruby-core  
> > about adding true Lisp-style macros to Ruby. My understanding is that  
> > while Ruby can do assorted flips and twists, it cannot do quite the same  
> > sort of things as found in Lisp (and I hope a true Lisper here can  
> > elaborate on this); I also believe that Matz is less than enamored with  
> > idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> > this, too).
> 
> --  
> Jim Freeze

---

<div class="post-metadata">

**Author:** ![Devin\_Mullins](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Devin\_Mullins](https://rubytalk.org/u/Devin_Mullins)\
**Post date:** [27 September 2005 12:21 UTC](https://rubytalk.org/t/lisp-macros/21128/9 "2005-09-27T12:21:07Z")

</div>

Devin Mullins wrote:

> The big thing Lisp has that Ruby can't do is code-as-data. I wish I could provide a good example of how that might be used practically, but it's been quite a while since I touched lisp.
> 
> Devin

Well, nobody's provided an example. The best I can do is provide more explanation. Since code is just (blah blah (blah blah)) -- that is, just a list -- and Lisp has the capability to delay evaluation (I think with an '), you can pass code into another function and have that function actually manipulate the internals of your code, and build some new code out of it. You could, maybe, write something that stripped all the print statements out at runtime... Crappy example...

Help! Is there a Lisper in the house?

Devin

---

<div class="post-metadata">

**Author:** ![Alex2](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Alex2](https://rubytalk.org/u/Alex2)\
**Post date:** [27 September 2005 02:18 UTC](https://rubytalk.org/t/lisp-macros/21128/10 "2005-09-27T02:18:26Z")

</div>

Joe Van Dyk wrote:

> > The big thing Lisp has that Ruby can't do is code-as-data. I wish I  
> > could provide a good example of how that might be used practically, but  
> > it's been quite a while since I touched lisp.  
> > &nbsp;&nbsp;&nbsp;
> 
> If anyone wants to chime in with an example of what code-as-data is or  
> how it could be used, I'd appreciate it!

--- foo.properties ---  
foo\_name = 'MyFoo',  
foo\_description = 'A code-as-data foo'  
foo\_question = 'Why is this useful?'  
foo\_answer = "Ah, well, sometimes it is"

--- foo\_properties\_loader.rb ---  
puts File.read('foo.properties')  
puts

load 'foo.properties'  
puts foo\_question  
puts foo\_answer

🙂

Alex

> **···**
>
> > On 9/26/05, Devin Mullins \<twifkak@comcast.net\> wrote:

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [27 September 2005 03:58 UTC](https://rubytalk.org/t/lisp-macros/21128/11 "2005-09-27T03:58:35Z")

</div>

Thank you!

Does Lisp have any other advantages over Ruby that I should be looking  
for? When would I want to use Lisp over Ruby?

> **···**
>
> On 9/26/05, Michael Schuerig \<michael@schuerig.de\> wrote:
> 
> > James Britt wrote:
> > 
> > \> Joe Van Dyk wrote:  
> > \>\> Whoops, this belongs on ruby-talk... Sorry.  
> > \>  
> > \> I trust the accidental exposure to Lisp wasn't too traumatizing.  
> > \>  
> > \> Anyway, there have been sporadic discussions both here and on  
> > \> ruby-core  
> > \> about adding true Lisp-style macros to Ruby. My understanding is that  
> > \> while Ruby can do assorted flips and twists, it cannot do quite the  
> > \> same sort of things as found in Lisp (and I hope a true Lisper here  
> > \> can elaborate on this); I also believe that Matz is less than enamored  
> > \> with idea of adding this to Ruby (and I hope a true Matz can elaborate  
> > \> on this, too).
> > 
> > I'm neither a true Matz nor a true Lisper. The basic facility Lisp  
> > macros offer over what is available in Ruby is that they do \*not\*  
> > evaluate their arguments. Where this is not an issue, you can get very  
> > far with what is there in Ruby.

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [27 September 2005 05:45 UTC](https://rubytalk.org/t/lisp-macros/21128/12 "2005-09-27T05:45:58Z")

</div>

> \> Joe Van Dyk wrote:  
> \>  
> \> Anyway, there have been sporadic discussions both here and on ruby-core  
> \> about adding true Lisp-style macros to Ruby. My understanding is that  
> \> while Ruby can do assorted flips and twists, it cannot do quite the same  
> \> sort of things as found in Lisp (and I hope a true Lisper here can  
> \> elaborate on this); I also believe that Matz is less than enamored with  
> \> idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> \> this, too).
> 
> Matz has said (at the Lightweight Language Conf) that Ruby will never  
> have macros because they are too easily abused, by the average person,  
> to mutate the language.

Was he joking?

> **···**
>
> On 9/26/05, Jim Freeze \<jim@freeze.org\> wrote:
> 
> > On 9/26/05, James Britt \<james\_b@neurogami.com\> wrote:
> 
> > Yes, Ruby has continuations and one can abuse them, but you have to  
> > be really smart. The average person won't even use them, let alone  
> > abuse them. 🙂

---

<div class="post-metadata">

**Author:** ![gabriele\_renzi3](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@gabriele\_renzi3](https://rubytalk.org/u/gabriele_renzi3)\
**Post date:** [27 September 2005 06:31 UTC](https://rubytalk.org/t/lisp-macros/21128/13 "2005-09-27T06:31:43Z")

</div>

Joe Van Dyk ha scritto:

> **···**
>
> > On 9/26/05, James Britt \<james\_b@neurogami.com\> wrote:
> > 
> > > Joe Van Dyk wrote:
> > > 
> > > > Whoops, this belongs on ruby-talk... Sorry.
> > > 
> > > I trust the accidental exposure to Lisp wasn't too traumatizing.
> > > 
> > > Anyway, there have been sporadic discussions both here and on ruby-core  
> > > about adding true Lisp-style macros to Ruby. My understanding is that  
> > > while Ruby can do assorted flips and twists, it cannot do quite the same  
> > > sort of things as found in Lisp (and I hope a true Lisper here can  
> > > elaborate on this); I also believe that Matz is less than enamored with  
> > > idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> > > this, too).
> > 
> > I'm just repeating what I've heard numerous times, but apparently, you  
> > can only get Lisp macros if the language has lots of silly irritating  
> > parenthesis. And since Ruby has syntax, it wouldn't be possible.
> 
> well you can get lisp macros only in a s-exp based language, but there are other mcro systems 🙂  
> Take a look at Dylan (close relative of lisp with more syntax), Nemerle and Logix. All succed to put a powerful macro system in a syntax which does not need prefix based everything 🙂

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [27 September 2005 07:41 UTC](https://rubytalk.org/t/lisp-macros/21128/14 "2005-09-27T07:41:43Z")

</div>

No, all you need is a way to manipulate the abstract syntax tree from  
code (or, indeed, the bytecode representation from code, for languages  
that work that way). Lisp gets it for free because s expressions \*are\*  
an abstract syntax tree.

martin

> **···**
>
> Joe Van Dyk \<joevandyk@gmail.com\> wrote:
> 
> > I'm just repeating what I've heard numerous times, but apparently, you  
> > can only get Lisp macros if the language has lots of silly irritating  
> > parenthesis. And since Ruby has syntax, it wouldn't be possible.
> > 
> > Or something. Don't pay attention to me. I have no clue what i'm  
> > talking about. ☹

---

<div class="post-metadata">

**Author:** ![Ben2](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@Ben2](https://rubytalk.org/u/Ben2)\
**Post date:** [27 September 2005 12:44 UTC](https://rubytalk.org/t/lisp-macros/21128/15 "2005-09-27T12:44:36Z")

</div>

This is a cop-out. Every time a new language comes around and  
doesn't support some feature, the reason is always "too easily  
abused". Macros in lisp are about abstraction. Like every other  
abstraction - interfaces, classes, pointers, etc, they can be abused  
horribly. They can also be a powerful tool.  
&nbsp;&nbsp;If I recall my CS 101, computer programming is built on the pillars  
of algorithms and data structures. Lisp and its variants are neat  
because they represent the code as a native data structure. With that  
in place it becomes easy to create algorithms to manipulate the data  
structure, changing the syntax as you write, and the code as it runs.  
If you're familiar with the more complex metaprogramming techniques  
C++ provides with templates, you'll start to get the idea of what lisp  
macros offer you. Macros are less limiting than C++ templates though,  
and more naturally represented.

&nbsp;&nbsp;Consider an array in Ruby whose first element is a method call:  
a = [method, param1, param2]  
eval "${a[0]} ${a[1]} ${a[2]}"  
If param1 becomes an array, that is a nested call:  
a = [method, [method2, x, y], param2]

In Lisp, if 'method' is a macro:  
a = [macro, [method2, x, y], param2]  
then macro gets 'expanded' at compile time WITHOUT evaluating the parameters:  
a = [method [do-crazy-thing param2 [do-cool-thing [method2, x, y] ] ]  
[[param2 method2, x, y] ] ]  
; Did I match all my braces?

I really like Lisp. 🙂

-Ben

> **···**
>
> On 9/27/05, Jim Freeze \<jim@freeze.org\> wrote:
> 
> > Matz has said (at the Lightweight Language Conf) that Ruby will never  
> > have macros because they are too easily abused, by the average person,  
> > to mutate the language.

---

<div class="post-metadata">

**Author:** ![Edward\_Faulkner](https://avatars.discourse-cdn.com/v4/letter/e/e9bcb4/32.png) [@Edward\_Faulkner](https://rubytalk.org/u/Edward_Faulkner)\
**Post date:** [27 September 2005 13:54 UTC](https://rubytalk.org/t/lisp-macros/21128/16 "2005-09-27T13:54:48Z")

</div>

Part of the attraction of Lisp macros is that they allow you to keep  
the core language very small, and add the features you want with  
macros. For example, as long as you have the lambda operator, you can  
define things like "while" and "let" as macros, not keywords. This is  
in fact how many Lisp implementations work, because it keeps the  
compiler/interpreter simple.

Another use for macros is to perform some of your computation at  
compile time, saving you from ever needing to perform it again at  
runtime.

In the general case, macros can be used to rewrite whole programs.  
For example, even though Lisp doesn't natively support continuations,  
you can build them with macros that rewrite your program into an  
explicit continuation-passing style.

Paul Graham's "On Lisp" is available online and contains several  
chapters about macros. It gives many more examples:

[http://www.paulgraham.com/onlisptext.html](http://www.paulgraham.com/onlisptext.html)

regards,  
Ed

> **···**
>
> On Tue, Sep 27, 2005 at 09:21:07PM +0900, Devin Mullins wrote:
> 
> > Crappy example...
> > 
> > Help! Is there a Lisper in the house?

---

<div class="post-metadata">

**Author:** ![Its\_Me](https://avatars.discourse-cdn.com/v4/letter/i/958977/32.png) [@Its\_Me](https://rubytalk.org/u/Its_Me)\
**Post date:** [27 September 2005 14:06 UTC](https://rubytalk.org/t/lisp-macros/21128/17 "2005-09-27T14:06:42Z")

</div>

"Lyndon Samson" \<lyndon.samson@gmail.com\> wrote in message

> Almost here with this [http://rubyforge.org/projects/parsetree/](http://rubyforge.org/projects/parsetree/) Just need  
> to able able to modify it and feed it back.

Will parsetree (and Rubyinline) run on Windows, and is a precompiled version  
available?

---

<div class="post-metadata">

**Author:** ![Robbie\_Carlton](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Robbie\_Carlton](https://rubytalk.org/u/Robbie_Carlton)\
**Post date:** [27 September 2005 14:50 UTC](https://rubytalk.org/t/lisp-macros/21128/18 "2005-09-27T14:50:29Z")

</div>

code as data is what makes lisp macros so powerful.

In a c macro you have the power of a little macro language to manipulate  
strings, in a lisp macro you have the power of lisp language to manipulate  
lisp data structures. I'll elaborate.

When the compiler sees a call to a macro it passes all of the arguments to  
the macro, before evaluating.  
so in a call like

(dotimes (i 10)  
(do-some-crazy-thing)  
(print i))

the macro dotimes is passed the list (i 10) and the list  
((do-some-crazy-thing) (print i))  
the macro can then operate on them as data, using the full power of lisp. At  
the end of all this, the macro returns another piece of data, a list, which  
is then interpreted as a lisp form, code, and evaluated.

If lisp code wasn't the same as lisp data, macros would be a lot less  
powerful as you would have to have two languages, one for manipulating lisp  
data, and another for manipulating lisp code (this is what you get in c).

Hope this helps. Sorry the example isn't very enlightening, it's difficult  
to illustrate the power of macros in (\< 500 words) as they're very  
complicated. If you'd like to know more\* ... learn lisp 🙂

Now I will stop with the lisp advocacy.

\*on lisp by Paul Graham is the bible on macros, but it's a little hard for  
someone who's new to lisp, try practical common lisp by Peter Siebel, (both  
are available free online).

> **···**
>
> On 9/27/05, Devin Mullins \<twifkak@comcast.net\> wrote:
> 
> > Devin Mullins wrote:
> > 
> > \> The big thing Lisp has that Ruby can't do is code-as-data. I wish I  
> > \> could provide a good example of how that might be used practically,  
> > \> but it's been quite a while since I touched lisp.  
> > \>  
> > \> Devin
> > 
> > Well, nobody's provided an example. The best I can do is provide more  
> > explanation. Since code is just (blah blah (blah blah)) -- that is, just  
> > a list -- and Lisp has the capability to delay evaluation (I think with  
> > an '), you can pass code into another function and have that function  
> > actually manipulate the internals of your code, and build some new code  
> > out of it. You could, maybe, write something that stripped all the print  
> > statements out at runtime... Crappy example...
> > 
> > Help! Is there a Lisper in the house?
> > 
> > Devin

---

<div class="post-metadata">

**Author:** ![Ptkwt](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Ptkwt](https://rubytalk.org/u/Ptkwt)\
**Post date:** [27 September 2005 18:11 UTC](https://rubytalk.org/t/lisp-macros/21128/19 "2005-09-27T18:11:47Z")

</div>

In article \<a39f6ad0050926185249a89232@mail.gmail.com\>,

> **···**
>
> Lyndon Samson \<lyndon.samson@gmail.com\> wrote:
> 
> > ------=\_Part\_8710\_13814260.1127785967504  
> > Content-Type: text/plain; charset=ISO-8859-1  
> > Content-Transfer-Encoding: quoted-printable  
> > Content-Disposition: inline
> > 
> > On 9/27/05, James Britt \<james\_b@neurogami.com\> wrote:
> > 
> > > Joe Van Dyk wrote:  
> > > \> Whoops, this belongs on ruby-talk... Sorry.
> > > 
> > > I trust the accidental exposure to Lisp wasn't too traumatizing.
> > > 
> > > Anyway, there have been sporadic discussions both here and on ruby-core  
> > > about adding true Lisp-style macros to Ruby. My understanding is that  
> > > while Ruby can do assorted flips and twists, it cannot do quite the same  
> > > sort of things as found in Lisp (and I hope a true Lisper here can  
> > > elaborate on this); I also believe that Matz is less than enamored with  
> > > idea of adding this to Ruby (and I hope a true Matz can elaborate on  
> > > this, too).
> > 
> > Almost here with this [http://rubyforge.org/projects/parsetree/](http://rubyforge.org/projects/parsetree/) Just need to  
> > able able to modify it and feed it back.
> > 
> > This [http://boo.codehaus.org/Syntactic+Macros](http://boo.codehaus.org/Syntactic+Macros) is also interesting reading.
> 
> Then this was this post by George Moschovitis about a year ago where he  
> implmented a simple macro system (more of a preprocessor, really):  
> [http://rubyurl.com/555](http://rubyurl.com/555)
> 
> Phil

---

<div class="post-metadata">

**Author:** ![Kev\_Jackson2](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@Kev\_Jackson2](https://rubytalk.org/u/Kev_Jackson2)\
**Post date:** [27 September 2005 04:08 UTC](https://rubytalk.org/t/lisp-macros/21128/20 "2005-09-27T04:08:26Z")

</div>

> Thank you!
> 
> Does Lisp have any other advantages over Ruby that I should be looking  
> for? When would I want to use Lisp over Ruby?

When you want to write your own language, Lisp is very useful, I'm sure that you can do this quite well with ruby (but I'm no ruby expert), but Lisp is teh poster child for domain specific languages.

Kev

[Next page](https://rubytalk.org/t/lisp-macros/21128.md?page=2)
