Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76488 invoked from network); 8 Nov 2016 19:43:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2016 19:43:18 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.86 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.86 mx105.easyname.com Received: from [77.244.243.86] ([77.244.243.86:33957] helo=mx207.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/F5-23587-AA822285 for ; Tue, 08 Nov 2016 14:34:03 -0500 Received: from cable-81-173-133-127.netcologne.de ([81.173.133.127] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1c4C9f-0004nI-7V; Tue, 08 Nov 2016 19:33:59 +0000 Reply-To: internals@lists.php.net References: To: David Walker , internals@lists.php.net, Andrea Faulds , lauri.kentta@gmail.com Message-ID: <3e3180e8-e9c2-abca-5228-221f8eae713d@fleshgrinder.com> Date: Tue, 8 Nov 2016 20:33:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC] Interval Comparison From: php@fleshgrinder.com (Fleshgrinder) On 11/7/2016 10:51 PM, David Walker wrote: > Sense be damed ;-) . I'd attribute it to an identity of sorts (if it was > to go all out with comparison chaining). Yes it makes little sense, in > practice, but the truth of it would be the same. > > 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 (<, <=, >, >=). As Andrea noted, python does allow for > arbitrary chains of comparison. I'm not exactly sure how precedence > would work with comparisons, rather, as I see it the comparison would > need to be expanded such > ``` > if (0 < $a < $b > 10) > ``` > would be akin to > ``` > if (0 < $a && $a < $b && $b > 10) > ``` > > I, of course, am only projecting a potential syntax, and I'm no yacc/ast > aficionado by any metric, but it'd seem to me that it'd be possible to > convert some stack of elements here into a recursive comparison. > This requires associativity, as Python has it. https://docs.python.org/3/reference/expressions.html#comparisons The problem, as explained in the Python reference, is that in `x < y < z` the variables `x` and `z` are never compared against each other. This, however, works great almost always and nothing is wrong in doing so in my opinion. That change would actually be brutally easy since we only need to change the `%nonassoc` to `%left` and we are done. https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L73 -- Richard "Fleshgrinder" Fussenegger