From: Paul Brannan Date: 2004-08-04T11:59:41+09:00 Subject: Re: Macros in Ruby On Wed, Aug 04, 2004 at 09:15:25AM +0900, Ben Giddings wrote: > The one place I've really missed macros is in debugging. I'm really > used to C macros that are really simple to type 'dbg(val);' but can > produce detailed valuable output: > > foo.c:132 do_it() val => 23 This looks more like logging than debugging. C macros typically make debugging more difficult, not less, because most debuggers don't let you "step into" a macro like you can with a function. > There are hackish ways to get something approaching this in Ruby, mainly > by twiddling with the 'caller' array, and using symbols to grab the name > of the symbol along with its value. That feels really hackish to me. > I'd feel slightly better about it if callers returned an array of > "SourceLine" objects, or something, and you could get the method name as > well. But it's still not quite up there with the ease of use of a C macro. The caller() method certainly has its problems. The API could be easier to use, but that doesn't make C macros better. You are comparing the design of two APIs (the Ruby API and the C preprocessor API), not macros versus no-macros. > I don't know if there's a middle ground, but I certainly lean towards > avoiding macros. What experience do you have with lisp macros or other non-C-preprocessor macros? Paul