From: Caleb Clausen Date: 2008-10-26T02:43:52+09:00 Subject: Re: RubyMacros 0.1.0 Released On 10/25/08, toomln wrote: >> When will you release some code to look at? > > I was close to asking the very same question. But then I saw "gem > install", so it's available as gem. Sorry, I didn't include any urls since I didn't have the rubyforge project yet. Maybe I should have posted one anyway... but now the project has been approved, and the code is up there, so try these: http://rubymacros.rubyforge.org/README.txt http://rubyforge.org/projects/rubymacros > > Anyway, how does this approach compare to: > > http://blog.drewolson.org/2008/06/ruby-and-macros-experiment.html I have to confess, I haven't looked into this project very much. This one is using strings to represent sexps... you can do a lot with that, but eventually you'll run into a glass ceiling of things you want to find in those strings that just can't be parsed readily with regexps. (My 'with' macro, (in the examples/ dir) is an example of the kind of thing that would be impossible.) The macros themselves require a distressingly large number of calls to eval. > http://weblog.raganwald.com/2008/06/macros-hygiene-and-call-by-name-in-ruby.html This is the best attempt I've seen to make something macro-like using ParseTree's syntax tree format. I'm amazed at Reg's ability to persuade ruby to do feats of gymnastics that I wouldn't have thought possible... but the result here is still slightly to very clunky, depending on which abstraction you're using. Here's the shorter of his two of his attempts to write an andand macro that operates like the && operator: called_by_name(:our_and) { |x,y| if temp = x y else temp end } Not so bad in itself, but all called_by_name's must be wrapped in a 'with', which must get tiresome. The longer one is too horrible to contemplate. The equivalent in RubyMacros is something like this: macro andand(a,b) :( if temp = ^a ^b else temp end ) #or maybe just :( ^a && ^b ) end If you want to write a sexp processor, rewrite can help you do that, and it should be possible to do things even macros can't that way. But it's very hard to use. This called_by_name looks considerably easier to use, but I think Reg says somewhere that it's only useful for a subset of what macros do... > May I humbly ask, how do I run the examples? I tried calling running > the example/*_wrap.rb scripts with ruby18 and ruby19 but only got > Syntax errors: Aaaaaag! Don't tell me I published broken code.... I did! Ok, I just fixed it, but gems hasn't found the new version yet, hopefully that won't take long, but til then, here's a couple of direct links to the fixed version: http://rubyforge.org/frs/download.php/45707/rubymacros-0.1.1.tgz http://rubyforge.org/frs/download.php/45706/rubymacros-0.1.1.gem (This is all because of a misguided attempt to keep rdoc from crashing... I give up on rdoc for the time being.) You were correct to try invoking the *_wrap scripts. "ruby -rubygems example/simple_wrap.rb" should do the trick.