in reply to Re^5: can sub check context for lvalue vs rvalue context?
in thread can sub check context for lvalue vs rvalue context?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: can sub check context for lvalue vs rvalue context?
by BrowserUk (Patriarch) on May 10, 2018 at 19:28 UTC | |
by perl-diddler (Chaplain) on May 10, 2018 at 21:50 UTC | |
by BrowserUk (Patriarch) on May 10, 2018 at 22:51 UTC | |
by perl-diddler (Chaplain) on May 11, 2018 at 16:19 UTC | |
by BrowserUk (Patriarch) on May 12, 2018 at 07:44 UTC | |
| |
by LanX (Saint) on May 11, 2018 at 17:02 UTC | |
| |
|
Re^7: can sub check context for lvalue vs rvalue context?
by ikegami (Patriarch) on May 11, 2018 at 19:51 UTC |