Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^10: Experimenting with Lvalue Subs

by BrowserUk (Pope)
on Jan 25, 2005 at 15:35 UTC ( #424898=note: print w/ replies, xml ) Need Help??


in reply to Re^9: Experimenting with Lvalue Subs
in thread Experimenting with Lvalue Subs

First off, you are assuming that an lvalue sub has to expose an actual attribute of the object.

Which is understandable as with the current P5 implementation and the proposed P6 implementation, where you cannot do anything after the assignment takes place--you are right.

But now imagine that the method was passed the rvalue when the method was invoked. Now you can do anything with it, like validate it, but also use it to derive some other value or a whole collection of values that then are then assigned to attributes of your object--none of which happen to have the same name as the method invoked.

The desirable feature is not the direct access to the underlying entity, it is the syntax that allows:

$obj->thing++;

in preference to

$obj->set_thing( $obj->get_thing() + 1 );

Whether thing is actually a piece of ram within the object or a conceptual attribute of it is secondary.

Equally, whether that example has to "call the function twice", once to get the value and once to modify it, is an implementation detail that should be transparent.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.


Comment on Re^10: Experimenting with Lvalue Subs
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-10-24 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (132 votes), past polls