FAQ

On Mon, Oct 20, 2014 at 11:11:22PM -0000, Father Chrysostomos wrote:
Yves Orton wrote:
On 20 October 2014 21:34, Father Chrysostomos <sprout cpan.org> wrote:
(foo())x256 should call foo() exactly once, as
should (foo())x0.
Forgive me for asking, but what says it should?
Nothing, as far as I can tell. (But nothing says that % should not
evaluate its right operand three times.)
(This is aside from the
fact that what you say is a reasonable expectation.)
The fact that it is a reasonable expectation, and backward-compatibil-
ity concerns, are sufficient reason to keep it that way.

If we skipped evaluating the left-hand side for 0 on the right, then
we would have to change the evaluation order of (foo()) x bar() as
well, if we want it to be predictable whether foo() is called.
We could conceivably optimise ("constant")x0 and ($foo)x0 and any
other op known not to have any observable side effects. But is
it worth it? (Oh no, I'm probably going to end up doing it! :-)
Aside from me being curious where this is specified, I think its probably
not worth it.
I'm beginning to lean in the opposited direction. I often use similar
constructs. And my only reason for avoiding them when I do is effi-
ciency, which suggests that perl ought to be worrying about effi-
ciency for me.
If I am to capture the current state of things, is it accurate to say:

- presently, both the LHS and RHS of expr1 x expr2 are evaluated, always.
- and the LHS is evaluated first, then the RHS.
- if any of the above could change, the possible things are:
   1. change the order to evaluate the RHS first,
   2. do not evaluate the LHS if the RHS is numerically zero (requires #1).

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 17 of 34 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedOct 19, '14 at 2:29a
activeOct 25, '14 at 9:51a
posts34
users9
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase