good chemistry is complicated,
and a little bit messy -LW
Re^9: Pre vs Post Incrementing variablesby BrowserUk (Pope)
|on Sep 13, 2010 at 09:19 UTC||Need Help??|
By the same logic in f($n) f should be passed the result (value) of $n, disallowing f from modifying $n.
If I pass variables to a function, then I expect to get reference to those variables:
But, if I pass sub-expressions to a function, I expect to get references to (temporary) variables containing the results of those sub-expressions. And in most cases that's exactly what I get:
I can even mutate those references to results without error:
but, and here is the significant point, those mutations do not modify the variable involved in the sub-expressions from which those results were derived:
It is only in the case of pre-increment expressions (and a few other similar anomalies), that the function receives a reference to the target of the sub-expression, rather than a reference to the result of it.
And the clincher that this is a bug, rather than an implementation specific optimisation allowable within the rules of the language definition, is that there is no good use for it.
The justification for many of the anomalies that exist in Perl, is that there are one or more very common cases where the anomalous behaviour is useful, Because it allows the capture, within a concise idiom, a piece of behaviour that is sufficiently commonplace to warrent it. This has no such justification.
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".
In the absence of evidence, opinion is indistinguishable from prejudice.