From: Ryan Pavlik Date: 2003-04-13T07:49:29+09:00 Subject: Re: The "!" and "?" characters. On Sun, 13 Apr 2003 02:19:11 +0900 Brian Candler wrote: > On Sun, Apr 13, 2003 at 01:04:53AM +0900, Ryan Pavlik wrote: > > I wonder at this... Lisp has macros, and they don't make it harder > > to read. > > Perhaps because it is impossible to make Lisp harder to read :-)) > I knew someone was going to say that. :-( ;-) > > c_for(i = 0, i < 200, i += 1) { > > ... > > } > > I'm not sure if that's the best example, because you can do that anyway if > st1/st2/st3 are proc objects: > > i = nil > c_for(proc {i = 0}, proc {i < 10}, proc {i += 1}) do > puts i > end Yes, but that's ugly. ;-) Also, it's slow, since it has to do a proc.call for each. Interestingly, a good bit of syntax modification _can_ be done with procs. (I've noted this a number of times in #ruby-lang.) I find not having macros because readability might suffer to be somewhat odd since, given blocks, you can do many of the same things (such as the WHILE {block} example in that one tutorial). However, macros make it nicer to read, in addition to some of the other important features. > I'm not a Lisp hacker (I've tried and failed there), but are Lisp macros > more powerful than that? I am by no means a Lisp hacker either... more an admirer. But there are a few things even in the above example that you shouldn't overlook: * The macro c_for would not start a new scope. Blocks do. * Given this, you can implement all the basic language in a form that makes them non-magical. This doesn't mean you can't cheat and optimize them, but that's transparent. * Blocks _are_ code. Macros _write_ code. That means you can have a block that writes new functions or macros. This is handy---things like attr_* already do it with eval()---and it makes it more efficient and aesthetic to do so. * The above all plays hand-in-hand with the ability to extend the parser, as in the bottom examples. (You can't write = or ++ using current ruby procs.) I'm sure there are some Lisp gurus around who could give some really cool examples of what macros can do. (Please? ;) > This kind of function composition was something I saw quite a lot of when > trying to learn Lisp. Function composition is cool. Macros are cool, too, though, and the two aren't mutually exclusive. Lisp is a very powerful N-generation language, _because_ of its ability to extend itself. New programming concepts or methodologies that come along can simply be absorbed, because the language is flexible. Of course, there is probably little desire to make Ruby something other than an object-oriented language. I have no personal desire to work in a non-OOP environment. (That's why I use ruby. ;) But that doesn't mean macros aren't powerful and useful. Necessary? No more than anything else. But useful, certainly---just like anything else. -- Ryan Pavlik "My plans are *always* practical! It's the laws of physics that get in the way of my success." - 8BT