good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^11: can sub check context for lvalue vs rvalue context?by BrowserUk (Patriarch) |
on May 12, 2018 at 07:44 UTC ( [id://1214414]=note: print w/replies, xml ) | Need Help?? |
but in non-lvalue context, I can return the variable directly in the belief that it is not being modified or assigned to. Your belief is wrong. In order for Perl to determine if the lvalue you return is ever modified, it would have to trace every usage or reference or alias of that variable right through to the end of the program. Eg.
You may think that is too elaborate an example that will never come up; but to be useful, your wantlvalue() would need to handle that and every other possibility. Even the 'simple case', of somefunc( x() ); conceals the fact that the lvalue returned by x() is aliased, and within somefunc() could be passed on to still more code as an alias or reference. For your "belief that it is not being modified or assigned to" to have any validity, Perl would need to follow every possible path to the end of the program before it decide whether to return true or false from wantlvalue(). Imagine the lvalue (or an alias or reference to it) is used in a conditional statement inside a loop; that could be dozens (hundreds/millions) of different possible paths, any of which might modify it. It would be impossible for a dynamic, interpreted language to provide an "is never modified" guarantee. And that's before you consider the possibility that an alias or reference to your lvalue might be used as part of a piece of run-time constructed code that gets eval'd. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
In Section
Seekers of Perl Wisdom
|
|