Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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:


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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424898]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-01-17 16:12 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (201 votes). Check out past polls.