Anonymous macros?
by Ingo Blechschmidt other posts by this author
Jun 13 2005 8:27AM messages near this date
Re: BEGIN {...} and IO
|
Re: Anonymous macros?
Hi,
just checking: Are anonymous macros allowed?
my $macro = macro ($x) { "100$x" };
say $macro(3); # 1003
Of course, anonymous macros can't be called at compile-time, like normal
macros:
my $macro = rand < 0.5
?? macro ($x) { "100$x" }
:: macro ($x) { "200$x" };
say $macro(3); # 1003 or 2003?
But they're still useful if I want to work with $macro references and
store them later, at compile-time, in a &-var:
my ¯o = BEGIN {
rand < 0.5
?? macro ($x) { "100$x" }
:: macro ($x) { "200$x" };
};
say macro 3; # reduced at compile-time to either 1003 or 2003
--Ingo
--
Linux, the choice of a GNU | The computer revolution is over. The
generation on a dual AMD | computers won. -- Eduard Bloch <edi@[...].de>
Athlon! |
Thread:
Ingo Blechschmidt
Larry Wall
|