Re: Re: [RFC] Arrow functions / short closures
| From: | Björn Larsson | Date: | Tue, 09 Apr 2019 21:52:17 +0000 |
| Subject: | Re: Re: [RFC] Arrow functions / short closures | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105185@lists.php.net to get a copy of this message | ||
Den 2019-04-09 kl. 17:23, skrev Björn Larsson:
Den 2019-04-09 kl. 12:19, skrev Nikita Popov:Just read the RFC a bit closer and saw that \$x is'nt possible, pity. Taking an example from chregu gist with arrow function inside a function call: - $waithandles = $this->urls->map(fn($url) => $this->fetcher->fetch($url)); - $waithandles = $this->urls->map(\($url) => $this->fetcher->fetch($url)); - $waithandles = $this->urls->map($url ==> $this->fetcher->fetch($url)); I would say that when lambda functions occurs in function calls I find the \ or ==> syntax more readable. Over & out //Björn LOn Tue, Apr 9, 2019 at 8:56 AM Björn Larsson <bjorn.x.larsson@telia.com> wrote:Maybe part of the reason it didn't attract to much support is that people are quite aware and respect the implementation difficulties. I recall a comment in this thread pointing in that direction. Well it's probably me being a long-time PHP user and now trying to learn RUST that finds the fn() syntax a bit confusing ;-) From that perspective I would prefer the \$x => $x **2 vs fn($x) => $x **2 or the ==> one. r//Björn L Hi again,Den 2019-04-08 kl. 16:06, skrev Nikita Popov:The ==> syntax is the other one I implemented ( https://github.com/php/php-src/pull/3945). The implementation is based on lexer lookahead, which is ugly but still manageable. I haven't seen much support for this variant in this discussion though. And of course, if there's no strong preference for ==>, I'd rather go with the variant that is easier for us (and all 3rd party tooling) to support from a technical perspective. NikitaOn Wed, Mar 13, 2019 at 4:56 PM Nikita Popov <nikita.ppv@gmail.com>wrote:tookHi internals, Motivated by the recent list comprehensions RFC, I think it's time weequivalentanother look at short closures: https://wiki.php.net/rfc/arrow_functions_v2 This is based on a previous (withdrawn) proposal by Levi & Bob. It uses the syntaxfn($x) => $x * $multiplierand implicit by-value variable binding. This example is roughlymodes.to:function($x) use($multiplier) { return $x * $multiplier; }The RFC contains a detailed discussion of syntax choices and bindingcomesRegards, NikitaHeads up: I plan to start voting on this RFC tomorrow if nothing newup. Most of the discussion was (as expected) about the choice of syntax. Ultimately I think there are many reasonable choices we can make here,butwe should stick to a specific proposal for the purposes of the RFC vote. None of the given arguments convinced me that some other syntax is *strictly* better than the proposed fn($x, $y) => $x*$y -- it's more a matter of some choices being slightly better in one case and slightlyworsein another. My personal runner-up would be \($x, $y) => $x*$y, but I suspect that there are some people who are more strongly biased against "sigil salad" than I am... NikitaHi, I recall that the perception of the ==> syntax in the Hacklang user community was quite positive. Of course it was implementation difficulties. Are they still to cumbersome in PHP? Personally I prefer that one being more readable or the \ one. Anyway, glad to see that short closures finally is on the road again!