On 9 May 2007, at 21:37, David Nicol wrote:
so if there were lisp-like macros available in perl, my sugar example
might be something like the following?
macro hashkeyaccessor(fieldname) { sub fieldname { $_[0]->
{fieldname}} };
hashkeyaccessor $_ for qw/FIELD NAMES GO HERE .../;
and I would save the trickiness of getting the interpolation level
right. That is
imagining a CPP macro... the LISP idea on macros is that the template
would be created at the optree level rather than the source level,
but its still
a template and replacement kind of deal. What am I missing?
You're missing that you can execute code at compile time that
determines what code you generate.
I'd recommend <http://www.gigamonkeys.com/book/> as a reasonable into
to Lisp for those who want to play. Macro chapter is <http://
www.gigamonkeys.com/book/macros-defining-your-own.html>.
Some devils brew of source filters and eval is the closest you'll get
in Perl 5.... Perl 6 with its explicit lexer/parser should give you
the full power of Lisp style macros.
Adrian (recovering Smug Lisp Weenie :-)