Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105185 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55567 invoked from network); 10 Apr 2019 00:55:19 -0000 Received: from unknown (HELO v-smtpout2.han.skanova.net) (81.236.60.155) by pb1.pair.com with SMTP; 10 Apr 2019 00:55:19 -0000 Received: from [192.168.7.8] ([213.64.245.126]) by cmsmtp with ESMTPA id DyfBh1gWuEqdODyfBhGKJJ; Tue, 09 Apr 2019 23:52:17 +0200 To: Nikita Popov Cc: Sara Golemon , PHP internals References: <582b57dc-42a0-582b-9471-2ede97ba584a@telia.com> Message-ID: Date: Tue, 9 Apr 2019 23:52:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------5A23F95DC594A196347987C6" Content-Language: en-GB X-CMAE-Envelope: MS4wfCcV5ICbP9u6qrPqafAzg6aaMpWQNdXwDZrzAtu1tDbPlijPKrh5afkWvd7BOjwhXASK7AUpQIPnCGAxuiiFGGY73ITaJn4mNEsE9pq1Qm0+VG1jxamd /BwJpSiWAqPE3OcP99ucrSeT+ByJpgSMeo2Xo80LTRmIEO2Gx8h0gVMriHJdDWhGI7YN7K6p6FJb8gh8I/OKGBUhbg21PU6jNJa2JIMiyyl4HYYdnvpJT/1a wn65MId1RD20sgGDRl5VqA== Subject: Re: [PHP-DEV] Re: [RFC] Arrow functions / short closures From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) --------------5A23F95DC594A196347987C6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Den 2019-04-09 kl. 17:23, skrev Björn Larsson: > Den 2019-04-09 kl. 12:19, skrev Nikita Popov: >> On Tue, Apr 9, 2019 at 8:56 AM Björn Larsson >> wrote: >> >>> Den 2019-04-08 kl. 16:06, skrev Nikita Popov: >>> >>>> On Wed, Mar 13, 2019 at 4:56 PM Nikita Popov >>> wrote: >>>>> Hi internals, >>>>> >>>>> Motivated by the recent list comprehensions RFC, I think it's time we >>> took >>>>> another 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 syntax >>>>> >>>>>       fn($x) => $x * $multiplier >>>>> >>>>> and implicit by-value variable binding. This example is roughly >>> equivalent >>>>> to: >>>>> >>>>>       function($x) use($multiplier) { return $x * $multiplier; } >>>>> >>>>> The RFC contains a detailed discussion of syntax choices and binding >>> modes. >>>>> Regards, >>>>> Nikita >>>>> >>>> Heads up: I plan to start voting on this RFC tomorrow if nothing new >>> comes >>>> up. >>>> >>>> Most of the discussion was (as expected) about the choice of syntax. >>>> Ultimately I think there are many reasonable choices we can make here, >>> but >>>> we 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 slightly >>> worse >>>> in 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... >>>> >>>> Nikita >>> Hi, >>> >>> 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! >>> >> 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. >> >> Nikita > 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, 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 L --------------5A23F95DC594A196347987C6--