http://www.perlmonks.org?node_id=424898


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.