ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
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 &macro = 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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved