Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105179 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72257 invoked from network); 9 Apr 2019 18:26:56 -0000 Received: from unknown (HELO v-smtpout1.han.skanova.net) (81.236.60.154) by pb1.pair.com with SMTP; 9 Apr 2019 18:26:56 -0000 Received: from [192.168.43.73] ([217.214.145.227]) by cmsmtp with ESMTPA id DsbGhbnvdSq0xDsbGhvgEj; Tue, 09 Apr 2019 17:23:51 +0200 To: Nikita Popov , Sara Golemon Cc: PHP internals References: <582b57dc-42a0-582b-9471-2ede97ba584a@telia.com> Message-ID: Date: Tue, 9 Apr 2019 17:23:50 +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: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-CMAE-Envelope: MS4wfE0l62mMmPVruGaj3cVkS9kwg9q6i5YdXm/e/W3q4S5RQodQaPPZSv6ixOI3CmKzSIc/kdqhDdoSTyfBM7w5KMD46fEUe7an21c6W4t4CEvZxwrVy39s +q0KElO13b/LTQ4nTQFhCjt9c3xhDjomJ+j6rBe8LJ8xAyxTr3dbphMlJEWfCfN3rcypsrwof31QR38loAqmN4n6imIibYlfoJEKuREvrvrwj4zysq8kLjgv V18DyoDorp1e5aD0rYKXtg== Subject: Re: [PHP-DEV] Re: [RFC] Arrow functions / short closures From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_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