Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 5354 days ago | link | parent

Oops!

  -(mac fexport (var . val)
  +(mac fexport (var val)
     `(fn-fexport ',var ,val))
That would be the bug you found, I think. ^^;

Thanks for the compliment. >.> Anyway, that pattern started when I saw http://awwx.ws/parsecomb0:

  (def on-result (f parser)
    (fn (p)
      (iflet (p2 r) (parser p)
        (return p2 (f r)))))
  
  (mac with-result (vars parser . body)
    `(on-result (fn (,vars) ,@body)
                ,parser))
Since then, I've noticed that defining one-use auxiliary functions like 'fn-fx and 'fn-fexport for macros is nifty in a few ways:

- Less need for w/uniq.

- More straightforward expansions and fewer gensyms when debugging.

- More one-liners, ironically at the expense of brevity. (The argument list is usually written three times this way: Once in the macro signature, once in the function signature, and once in the macro body.) At least it's in bite-size pieces. ^_^;

I've also noticed that 'after and 'protect have the same pattern, and that at least one other person here (don't remember who) uses it as extensively as I do. So it's probably as good as advertised. :-p



3 points by aw 5354 days ago | link

Yes, I find I' often write a macro whose only purpose is to allow a "body" to be written without having to enclose it in a function. For this specialized purpose, it'd be nice to have a macro defining macro to do that... though I haven't thought about how to do that myself yet.

-----