When I return an lvalue, in my mind, I'm returning the address of an object so that the compiler/interpreter can put something in it (has happens to the left side of an assignment).
Vs. if I return an rvalue, In my terminology, I'm only returning the value that was in that address -- so the compiler/interpreter can't assign a new value into the variable location.
If I return an lvalue, the compiler can store a new value. But it can also propagate that value to another lvalue. No problem: I don't care. What I care about is detecting that my lvalue sub has been assigned to (whether or not the value changes is irrelevant).
The rvalue context I would detect in a statement like:
would allow me to return an actual value and not a tied var.if ($p->url) {...}
It's the 'lvalue' case where I need to presume that the value in 'url might change, and thus return a more expensive (ex. tied) version so I can update the url's component values.
I don't see how that is problematic.
In reply to Re^6: can sub check context for lvalue vs rvalue context?
by perl-diddler
in thread can sub check context for lvalue vs rvalue context?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |