Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96748 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93245 invoked from network); 6 Nov 2016 21:44:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2016 21:44:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=dave@mudsite.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dave+php@mudsite.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain mudsite.com designates 209.85.213.44 as permitted sender) X-PHP-List-Original-Sender: dave@mudsite.com X-Host-Fingerprint: 209.85.213.44 mail-vk0-f44.google.com Received: from [209.85.213.44] ([209.85.213.44:32839] helo=mail-vk0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/37-33116-824AF185 for ; Sun, 06 Nov 2016 16:44:10 -0500 Received: by mail-vk0-f44.google.com with SMTP id 137so59598889vkl.0 for ; Sun, 06 Nov 2016 13:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mudsite-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=M1GceK6PpzrHnxLBzW3W7CeJfAA44U7Ym1JQUCZZ5h8=; b=qnpsjyIZ6j0jyjMoKIWiACdcLXpJRBgwMMR4BFMmYAvxqUJT7dVwgyU1vGKfbVG5u7 464iaYStHKywJ2rRr+30OMoHUjvhLayjoSpjfHhVPM+cpfOOI4u+wm8RJP1FAF5WlB/o n13fqcqURo9UntKkYFd/FvNtr9T8YTKmXQxvXYqxyC6Fx9861vUbnQymPb1wlK+KeWs2 qxTcm8qe96Y6+PpHuZhRsJXXIgK84p5VA9yUbbxf31A7FFcCeLrBHRAheTIC7NWL+yzV 2h+aPitTI0ULejaOrpHMjoq+nwwOIlA9bOx5sVZRTojjlK8bkP1Rw/YxXmruNEpSXPI/ PJlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=M1GceK6PpzrHnxLBzW3W7CeJfAA44U7Ym1JQUCZZ5h8=; b=MiLtp5bBxtcGnYxzCvVvnvC/qd8PlyIB5MQYGblUHjxQArEy1Z8zRQ5KLqrkLIERHh 34nQkiSXMA9xyzH+/xYqGl227pj/anj7b8vM6IS7ma99tPPwAkM7RM1Ke8MBUCxdp8TI Bg1gi7iH8r1mXHAkr7XoN4dyQIYiYNNl28FRwQMESahkpyAI18WofIXgbxF78HTM3x2P 790cXyUrJdQhs6ua3cmBg/njrbzpr6ygVfi8UcYm2Srqag3XZgOqRU24aYjq6KOctt4K JS8Ker+pgr9YFmfpweOxiWR8zHp/UFvQuqBLaH28hje03SnFNLSbIGYnJNGJbT1+RHUl /5/g== X-Gm-Message-State: ABUngvfWRAxpYYyuVlORqkJkZXTtMjnpT3MDBmZ8lizUWAx1Tz4XDO8qbpeLpkoE407UPA1gaiuUBYYnEnpQdw== X-Received: by 10.31.202.193 with SMTP id a184mr1696953vkg.134.1478468646495; Sun, 06 Nov 2016 13:44:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 06 Nov 2016 21:43:55 +0000 Message-ID: To: David Rodrigues , PHP Internals Content-Type: multipart/alternative; boundary=001a114dcec27cae160540a8ce70 Subject: Re: [PHP-DEV] [RFC] Interval Comparison From: dave+php@mudsite.com (David Walker) --001a114dcec27cae160540a8ce70 Content-Type: text/plain; charset=UTF-8 On Sun, Nov 6, 2016 at 1:59 PM David Rodrigues wrote: > I guess that the biggest problem is about the code parsing. Currently PHP > should supports what you wrote, but with another meaning. And personally I > think that this feature is not too common on programming language in > general, once that it is possible from first format (maybe more clear too). > > Em 6 de nov de 2016 6:30 PM, "Fleshgrinder" > escreveu: > > > Validating whether a number is within a closed or open interval is > > currently possible only via a construct like the following: > > > > ``` > > if (0 < $x && $x < 42) { > > echo 'x is in (0, 42)'; > > } > > > > if (0 <= $x && $x <= 42) { > > echo 'x is in [0, 42]'; > > } > > ``` > > > > 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]'; > > } > > ``` > > > > Richard, I'd be a +1 on this. I dislike having the double comparison all over checking for bounds, and have for quite a while. Akin to what David brought up, https://3v4l.org/7MvlB. It seems the requested syntax is not valid in any PHP version testable here. I can't speak to the complexities of implementing something like that, but would find it useful. Of course, you'd have to worry about other conditions like ``` if (0 < $x > 20) ``` By worry about, I mean, should it be invalid syntax, or, should it be optimized to be `20 < $x`? I'd say you'd have to maintain the gt/lt for chaining. Then I'd wonder about similar syntax to check if 2 variables are both greater than 0, but one greater/equal to the other: ``` if (0 < $x <= $y) ``` -- Dave --001a114dcec27cae160540a8ce70--