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
Re: proposal: binding with a function
by Ingo Blechschmidt other posts by this author
Jun 23 2005 8:29AM messages near this date
Re: proposal: binding with a function | Re: proposal: binding with a function
Hi, 
 
Juerd <juerd <at>  convolution.nl> writes: 
>  Piers Cawley skribis 2005-06-23 15:30 (+0100): 
>  > Brent 'Dax' Royal-Gordon <brentdax <at> gmail.com> writes: 
>  > > As I've said before, Perl supports `alias`--it's just spelled `:=`. 
>  > Here's a rubyish idiom: 
>  >   my &old_behaviour := &function; 
>  >   &function := sub { try_some_stuff || &old_behaviour } 
>  > Except, with binding it doesn't work like that, you end up with an 
infinite 
>  > loop.  
>   
>  I still think subs should have a value, than can be copied :) 
>   
>      my &old_behaviour = &function; 
>      &function = sub { try_something || &old_behaviour }; 
 
I absolutely agree! 
 
But: Your example won't work correctly, as function() would 
return a Code reference (&old_behaviour) instead of calling 
old_behaviour, wouldn't it? 
 
I think all of the following should work: 
 
    my &old_behaviour = &function; 
    &function = sub { try_something() || old_behaviour() }; 
 
    my &old_behaviour = &function; 
    &function := sub { try_something() || old_behaviour() }; 
 
Additionally, with nothingmuch's lazy {...} proposal, the 
following should work, too (I think): 
 
    my &old_behaviour = &function; 
    &function = lazy { &try_something || &old_behaviour }; 
 
    my &old_behaviour = &function; 
    &function := lazy { &try_something || &old_behaviour }; 
 
 
--Ingo 
 
--  
Linux, the choice of a GNU | When cryptography is outlawed, bayl bhgynjf 
generation on a dual AMD   | jvyy unir cevinpl!   
Athlon!                    |  
Thread:
B=C1RTH=C1ZI_Andr=E1s
Larry Wall
Damian Conway
Ingo Blechschmidt
Juerd
Carl Franks
B=C1RTH=C1ZI_Andr=E1s
B=C1RTH=C1ZI_Andr=E1s
BÁRTHÁZI András
Brent 'Dax' Royal-Gordon
BÁRTHÁZI András
Brent 'Dax' Royal-Gordon
BÁRTHÁZI András
Abhijit Mahabal

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