Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

One of things that makes Ruby shine is the ability to create Domain Specific Languages better, like

Though one can duplicate these libraries in LISP through macro, I think Ruby's implementation is more elegant. Nonetheless, I think there are cases that LISP's macro can be better than Ruby's, though I could not think of one.

So, in what area is LISP's macro better than Ruby's "ability" to create DSL, if any?


I've asked this because modern programming languages are approaching the LISP singularity, like

  • C got macro expansion preprocessor, though very primitive and prone to error
  • C# has attributes, though this is a read-only, exposed through reflection
  • Python added decorator, that can modify the behavior of the function (and class for v 3.0), though feels quite limited.
  • Ruby TMTOWTDI that makes elegant DSL, if care is applied, but in Ruby way.

I was wondering if LISP's macro is only applicable to special cases and that the other programming language features are powerful enough to raise the abstraction to meet the challenges today in software development.

share|improve this question
I'm not quite sure why there's close votes on this. I though this is the kind of question we want ? Interesting, thought provoking and the scope is defined quite well. – Tim Post Jun 3 '11 at 6:36
Try to implement something like this in Ruby: – SK-logic Jun 3 '11 at 14:21
@Tim Post: One problem is that this really isn't an easy question to answer unless you know both Common Lisp and Ruby well. Another is the fairly ignorant references to other languages, which may annoy purists: there is no language called C/C++, and the significant part of C++ is the template system, and the suggestion that Common Lisp's macro system is only applicable to special cases. Fundamentally, it's a good question, but it's written badly and is hard to answer. – David Thornley Jun 3 '11 at 14:45
@David Thornley, I've updated the post, particularly on C\C++ , and place emphasis on C. As for Common Lisp, I was feeling that since other programming languages have higher abstraction, it's macro feature is for special case. I posted the question, hoping that others will show me that CL's macro isn't for special case is still a powerful feature. – OnesimusUnbound Jun 3 '11 at 14:58
@OnesimusUnbound: I really would include C++'s templates in your list of language examples, since they are at least theoretically capable of any computation the Lisp macro system can do. As far as Lisp's macros go, get hold of some good Common Lisp code (there's plenty of F/OS Lisp code out there), and search for "defmacro" (you may want to do a case-insensitive search). You'll probably find a whole lot of them. Consider that macros are harder than functions to write and get right, and you'll realize they have to be generally useful. – David Thornley Jun 3 '11 at 15:09
up vote 20 down vote accepted

Read On Lisp and then decide for yourself.

My summary is that Ruby is better at providing convenient syntax. But Lisp wins, hands down, at the ability to create new abstractions, and then to layer abstraction on abstraction. But you need to see Lisp in practice to understand that point. Hence the book recommend.

share|improve this answer
+1 , A very good book to read. – Tim Post Jun 3 '11 at 6:34
"Let Over Lambda" covers much similar ground. Also recommended reading. – John R. Strohm Jun 3 '11 at 12:32
But Lisp wins, hands down, at the ability to create new abstractions, and then to layer abstraction on abstraction. Now I know why . . . – OnesimusUnbound Jun 3 '11 at 14:13
It is not a big deal to provide any kind of syntax on top of Lisp. In fact, much easier than with Ruby, thanks to the reader macros. – SK-logic Jun 3 '11 at 14:22
@SK-logic: True. However Lispers shy away from reader macros because once you go down that route it no longer feels like a Lisp. In fact some variants of Lisp, such as Clojure, reserve reader macros for the language designer. – btilly Jun 3 '11 at 16:38

Ruby's facilities for DSL authoring don't change the nature of the language. Ruby's metaprogramming facilities are inherently tied to Ruby syntax and semantics, and whatever you write has to be shunted into Ruby's object model.

Contrast that with Lisp (and Scheme, whose macro facilities differ), where macros operate on the abstract program itself. Because a Lisp program is a Lisp value, a macro is a function mapping one essentially arbitrary syntax to another.

Effectively, a Ruby DSL still feels like Ruby, but a Lisp DSL doesn't have to feel like Lisp.

share|improve this answer
+1: LOOP doesn't feel very Lispy, as an example of a DSL. – Frank Shearar Jun 3 '11 at 12:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.