Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5795 invoked from network); 7 Nov 2016 01:17:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Nov 2016 01:17:50 -0000 X-Host-Fingerprint: 2.216.52.233 unknown Received: from [2.216.52.233] ([2.216.52.233:5056] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/A8-33116-C36DF185 for ; Sun, 06 Nov 2016 20:17:49 -0500 Message-ID: <96.A8.33116.C36DF185@pb1.pair.com> To: internals@lists.php.net References: Date: Mon, 7 Nov 2016 01:17:45 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 2.216.52.233 Subject: Re: [RFC] Interval Comparison From: ajf@ajf.me (Andrea Faulds) Hi, Fleshgrinder wrote: > It is not very readable and repetitive. It would be interesting to > support a more mathematical notation for this: > > ``` > if (0 < $x < 42) { > echo 'x is in (0, 42)'; > } > > if (0 <= $x <= 42) { > echo 'x is in [0, 42]'; > } > ``` > > I cannot judge how complicated it is to extend the Bison definitions to > allow this. However, if there is interest I'm sure there is a way. :) > Python supports this, I believe it lets you use arbitrary chains of comparisons. PHP is in the fortunate position where the associativity of the comparison operators is undefined. That is, `0 < $x < 42` is currently invalid syntax. Some other languages made the (in my view) mistake of defining a precedence here, so that it gets interpreted as `(0 < $x) < 42`, which is (generally?) useless. PHP doesn't have this problem. I've wanted to do this myself, but figuring out how to implement it was tricky, so I didn't spend much time on it. But it's certainly possible, and I'd appreciate this if it was added. Thanks for bringing it up! -- Andrea Faulds https://ajf.me/