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: Assigning Proxy objects
by Larry Wall other posts by this author
Jun 14 2005 9:49AM messages near this date
Assigning Proxy objects | proposal: binding with a function
On Tue, Jun 14, 2005 at 12:33:34PM +0000, Ingo Blechschmidt wrote:
: Hi, 
:  
:   sub proxy () is rw { 
:     return new Proxy: 
:       FETCH =>  { 42 }, 
:       STORE =>  -> $new { 23 }; 
:   } 
:  
:   say proxy();        # 42 
:   say proxy() = 40;   # 40, 23, or 42? 
:  
: Currently I think the last line should output 40, consider: 
:  
:   sub innocent_sub ($var is copy) { 
:     my $foo = ($var = 40); 
:     # Do something with $foo, relying on $foo being 40. 
:   } 
:  
:   { my $x = "does not matter"; innocent_sub $x } 
:   # Works 
:  
:   { my $x := proxy(); innocent_sub $x } 
:   # Would break if (proxy() = 40) would not return 40. 
:  
: But I can argue that the return value of Proxy object should 
: be the return value of the code given by FETCH in the Proxy 
: object construction, too... 
:  
: Opinions? 

The intention is that lvalue subs behave in all respects as if they
were variables.  So consider what

    say $nonproxy = 40;

should do.  This also extends to other operations than assignment:

    temp $foo.bar() = 40;

or the very-nearly-Software-Transactional-Memory-oriented:

    let $object.attribute() = 40;	# hope this sticks...

Larry
Thread:
Ingo Blechschmidt
Larry Wall

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