From: Yohanes Santoso Date: 2004-08-05T19:45:15+09:00 Subject: Re: Macros in Ruby surrender_it@yahoo.it (gabriele renzi @ google) writes: >> def_with_docstring(Object, "foo", "returns arg", "arg", "arg") >> >> Object.new.foo("hi") # => "hi" >> >> Yes, I am aware you can do more sophisticated implementation so you >> can make the above nicer. Yet, as nice as it will be, it won't be as >> simple as the example with macro; there will be quirkiness caused by >> the language syntax. > > not that much, did you see the MetaTags system or the various > implementations of docstrings? > > Something on the lines of: > > doc 'this things does foo' > def foo > ... > end More like: class_info <<-DOC !Class: MyClass !Desc: This class does something !attr a: A: The "A" attribute !attr b: B DOC class MyClass ... end and this is what the doc has to say about the '!Class' tag: !Class - A string indicating the fully-qualified class name. This is a required field. Robert's example is about similar to what MetaTags does. Thus, they both make one to repeat one self; you have to say: "this docstring is for this method of this class", even if the information is available nearby. I think this counts as quirkiness. My point was not whether it is possible to do something in Ruby. The point was to show Rando Christensen that macro can be used to enhance clarity as well as to obfuscate, and that some things are easier done with macro then without. I think my example shows that with macro, you can extend the language naturally (instead of having to repeat yourself if done within the language's limitation). >> For example, rake has this in its documentation: "NOTE: Because of a >> quirk in Ruby syntax, parenthesis are required on rule when the first >> argument is a regular expression." > > IIRC this is related to bison not being good enough :) Somewhere, somehow, there will always be deficiencies. With macro, you can alleviate those somewhat. Not that I think macro would help rake in the above case since that is a syntax problem, rather than semantic problem (I have no idea if macro can save you from invalid syntax since the only macro system I've used is lisp's where the syntax is not as rich as ruby's and also doesn't work if you have an invalid syntax anyway). I am not advocating for macro in Ruby. I am neutral; I do not care if there is macro or not. If there is macro, then that's great, although there are only so many legitimate usages. If there isn't, it is also not such a big of a loss since there are only few legitimiate usages. Even the above example (repeating yourself), can be somewhat eliminated with the help of a good editor. Have a nice day, thanks for the input! I didn't know about MetaTags before. Thank you. YS.