Re: [RFC] Interval Comparison

From: Date: Sat, 12 Nov 2016 16:56:13 +0000
Subject: Re: [RFC] Interval Comparison
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-96860@lists.php.net to get a copy of this message
On Sat, Nov 12, 2016 at 9:47 AM Christoph M. Becker <cmbecker69@gmx.de> wrote: > On 12.11.2016 at 17:21, David Walker wrote: > > > Should > > $a = 1; > > var_dump(1 < $a++ < 3); > > > > (expanded into numbers) be evaluated as: > > 1 < 2 && 2 < 3 - True > > or > > 1 < 2 && 3 < 3 - False > > In my opinion, that should evaluate to > > 1 < 1 // false > > because we have a post-increment operator, and it seems to me that the > expansion defined for Python[1] makes most sense: > Double my oops, I meant a pre-increment. > > > Comparisons can be chained arbitrarily, e.g., x < y <= z is > > equivalent to x < y and y <= z, except that y is evaluated only once > > (but in both cases z is not evaluated at all when x < y is found to > > be false). > > [1] <'>6~hY > @ümÁ{https://docs.python.org/2/reference/expressions.html#not-in> > I concur with this, that each term should only be evaluated once, in more what Lauri defined: a < ($tmp1 = b) && $tmp1 < ($tmp2 = c) && $tmp2 < d Which would ensure that each position is evaluated once, in a left->right fashion. And I doubly concur that evaluation is short circuited (per my wrong example, you corrected): $a = 0 1 < $a++ < $a++ < 3 ~~ 1 < 1 // false. $a would be 1 after this line. -- Dave

« previous php.internals (#96860) next »