Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104642 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45945 invoked from network); 11 Mar 2019 02:57:48 -0000 Received: from unknown (HELO mail-ua1-f54.google.com) (209.85.222.54) by pb1.pair.com with SMTP; 11 Mar 2019 02:57:48 -0000 Received: by mail-ua1-f54.google.com with SMTP id e15so944228uam.3 for ; Sun, 10 Mar 2019 16:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xGHL9jBtEOdbUkvCI1Ikf6eT/3SoBM7tri5ISFhlavw=; b=LiKdt1aDLAaj0L20Y1QabKjWFYWmOUN5jQaoo+lTL6/9B7Rc9AkojwpJ2cq6Iq6ZfR PD/JXO02Y2rDMwCdqkULBmJ/PYIYTDMmvQlC2Rz93989e4VYqQwZ7g4OwaK/ZxQdBCd0 p5Tu8wbMxERa9mJS7BSf35o5PnbEtoWOdCYb5HXHLuTKaofK49aF8OC0mmIApdOEK3oi ONXnfg4d4FfpMED7FGVEVZL/BsYRJt5OnAKp/PZd8J1aO+9vlax6WuS1w4BWVJJjXxwb c6UC+gU4ZkUJtqZCXT9jtYUF5C+WTMMQ7dkWxBhXbPTFG4gdMBKJZXpLQlxMnC5ZWSzv fF3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xGHL9jBtEOdbUkvCI1Ikf6eT/3SoBM7tri5ISFhlavw=; b=bCNBRp1R3uf02PLx0sD4tMtWuApZDzpjyPdSkKTugYt5vv2tXW+K7WHtj8dqWinXdC f/CGx0cHifYZakvatndQr2X2naLezOz5noO9/eRYBXjqduKkZYzB741xvycMobMyDWEP bJ58QWAYSoycSF9UNtzkMkBdHQNS/5OVrDrGtXQNLSMH9wESnq5ra6C+4CifsacRpBv/ N4eVROSkHQAW0KYO0J7oh0MjkXb+WoHHM1kkacoLUy6D0t2MYrf03BVWkowHruvTI/of m0ihI/KgQCqsWFH8Z7ClzYaMLH1KalP3uLbUUbXpznXdE3zmN7gGFOGneuct9D7O4wJQ ikcw== X-Gm-Message-State: APjAAAVhTiaz+h3IF6HJsUa4WexFY8EzUsxzevzvoo8JQ6WpXYVZtJw3 ZnRsfm6Kvq5OfH2lcma1XuGTydNwCICZP6Eaqn1z6AaE68I= X-Google-Smtp-Source: APXvYqxHaUiN3XYKUnVu6wksMzPs8gyZWBttP8uixdhbww5445OsHrNm4qS6Ll3yUrbPA6+asQTp7c+QVJkt9xSA2j8= X-Received: by 2002:ab0:a98:: with SMTP id d24mr15062872uak.124.1552261637510; Sun, 10 Mar 2019 16:47:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 11 Mar 2019 00:47:04 +0100 Message-ID: To: Larry Garfield Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000809b0a0583c613b9" Subject: Re: [PHP-DEV] RFC Draft: Comprehensions From: george.banyard@gmail.com ("G. P. B.") --000000000000809b0a0583c613b9 Content-Type: text/plain; charset="UTF-8" On Sun, 10 Mar 2019 at 22:45, Larry Garfield wrote: > Hello, peoples. I know it's been discussed once or twice before on the > list, many years ago, but not recently. I therefore feel OK putting forth > the following draft proposal for Comprehensions, aka "compact generators", > in PHP: > > https://wiki.php.net/rfc/comprehensions > > Sara Golemon has written a preliminary patch that is partially complete > (see the RFC link for details, it's impressively simple), but unfortunately > doesn't have the bandwidth to complete it at this time. I am therefore > looking for collaborators with more knowledge of internals than I (which is > almost everyone) to help finish it up. > > The syntax proposed is also subject to revision if a terser but still > lexer-friendly alternative can be proposed. > > At the moment I'm not calling this Proposed yet, as I don't feel > comfortable doing so until someone else is on board to finish coding it. > That said, if someone wants to weigh in on the concept for now (hopefully > supportively) that's also fine. > > Anyone excited enough to help finish the job? > > (This is my first RFC collaboration, so if you're going to smack me for > goofing something please be gentle about it.) > > -- > Larry Garfield > larry@garfieldtech.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Hello Larry, I do like the proposal of adding comprehensions to PHP, and I do agree with you that short closures do not replace a short closure synstax (as even with them it is still not ideal). However I have a couple of complaints, JS comprehensions have not become a standard and have been removed from my understanding [1][2]. Secondly I don't really understand the argument for using `for` instead of ` foreach` Sure it saves 4 chars but the PHP version compared to the Python uses `yield ` which already lengthen it, I do understand why it is there because it is a generator. But Python using `for` makes more sense, imho, because its syntax is `expression for item in iterator (if condition)`. Now maybe what I am going to say is total BS because I don't know *how* the engine works, but wouldn't also use foreach make it easier for the lexer as it already know the `as` keyword? Maybe if we want to mimic the Python syntax why not use a syntax like: `(yield expression) foreach iterator as item (if condition)` I also suppose that comprehension chaining is possible because it returns a generator. Small nitpick but shouldn't the `current` method link to the Generator->current instead of the function `current` which only works with arrays? Also would it be possible to use a string as an iterable expression? Because currently it's not possible to foreach a string (but that's maybe more the scope of another RFC). Best regards George P. Banyard [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Generator_comprehensions --000000000000809b0a0583c613b9--