Re: [RFC] Interval Comparison

From: Date: Tue, 08 Nov 2016 12:25:13 +0000
Subject: Re: [RFC] Interval Comparison
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-96769@lists.php.net to get a copy of this message
On 2016-11-07 23:51, David Walker wrote:
On Mon, Nov 7, 2016 at 1:38 PM Fleshgrinder <php@fleshgrinder.com> wrote:
We are only extending binary to ternary for <= and <.
I realize that my comment, and question were going a bit off-topic with going on about the chaining of comparisons, but I'm interested in it more because I wonder which would be harder to implement. It would seem to me that it would be harder to implement a means in which you only allow one additional layer of comparison, rather than abstract chaining of comparisons (<, <=, >, >=).
I'm pretty sure that a three-part comparison is easier to implement. It can be kind of hard-coded as a new type of syntax, somewhat like the ternary operator. Personally I'd prefer the full Python-style chaining. It's a lot more useful, especially for cases like 0 < $a <= $b < $upper_limit. One possible implementation idea (not knowing anything about Zend): Comparison (a<b) would return a pair of data, the result and the latter value. If this was the last comparison or the result was false, the value will be dropped and the comparison ends. Else the result (true) will be dropped and the comparison will go on. -- Lauri Kenttä

« previous php.internals (#96769) next »