Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94597 invoked from network); 30 May 2017 22:46:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 22:46:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain telia.com from 81.236.60.156 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.156 v-smtpout3.han.skanova.net Received: from [81.236.60.156] ([81.236.60.156:43234] helo=v-smtpout3.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/78-43873-B56FD295 for ; Tue, 30 May 2017 18:46:52 -0400 Received: from [192.168.7.8] ([195.198.188.252]) by cmsmtp with SMTP id FpuZdMkzZARCaFpuZdZGBl; Wed, 31 May 2017 00:46:47 +0200 To: Levi Morrison Cc: Derick Rethans , PHP internals References: Message-ID: Date: Wed, 31 May 2017 00:46:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: sv X-CMAE-Envelope: MS4wfLMnAdORW5U0+qXHSav/MonCq50Gq0QLcDBlZUlY+CO+3W8NlD7efppwB08UGiY9bR4DFBW8e3zijuX5szGWbE8ZXyyiWV17XchIqSQlvXu6hYmqDmqE KVWuvkR/l9ToPmHI4SAvXmlY02K84Gql9H1+W1Qwfsxo43tmvYi30kE0o8ISgXzGDJn0XgH6REy43DdVmVl6HXQrzk9Jm3FKH5+IkWLpCv5aE4So9kVHzdvQ Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2017-05-31 kl. 00:26, skrev Levi Morrison: > On Tue, May 30, 2017 at 3:37 PM, Björn Larsson > wrote: >> Den 2017-05-30 kl. 21:40, skrev Derick Rethans: >> >>> On Tue, 30 May 2017, Levi Morrison wrote: >>> >>>> Internals, >>>> >>>> The previous discussion thread has died down significantly and so I'd >>>> like to start a new one to refocus. This message has some redundant >>>> information by design so people don't have to reference the other >>>> thread so much. >>>> >>>> Based on the discussion there are a few different syntax choices >>>> people liked. Overall it's a feature that people seem to want but >>>> everyone seems to prefer a different syntax choice. >>>> >>>> 1. fn(params) => expr >>>> 2. function(params) => expr >>>> >>>> 3. (params) ==> expr >>>> 4. (params) => expr >>>> >>>> Note that 3 and 4 require a more powerful grammar and parser and that >>>> 4 has ambiguities. I think we can work around them by rules -- only >>>> mentioning it because its popular because of JavaScript and do not >>>> prefer this at all. >>>> >>>> Note that 1 requires a new keyword. >>>> >>>> Option 2 looks the best from that perspective but is by far the >>>> longest; remember people are partially interested in this feature >>>> because they want shorter closures which this doesn't really help. >>>> >>>> This is why everyone is so divisive. All options have drawbacks. >>>> Additionally some people don't like binding by value and would prefer >>>> ref, and others really would be against by-ref. >>>> >>>> Which brings me to an option I don't think was ever discussed on list: >>>> >>>> 5. >>>> [](params) => expr // binds no values >>>> [=](params) => expr // binds by value >>>> [&](params) => expr // binds by reference >>>> >>>> It has quite a few good qualities: >>>> >>>> - No new keywords >>>> - Can choose between reference and value >>>> - Concise >>>> - Has precedence in C++, a major language >>>> - Can be done in our existing grammar and parser[1] >>>> - Can be extended to allow explicit binding of variables: >>>> // all equivalent >>>> // y is bound by value, array by reference >>>> [&, $y]($x) => $array[] = $x + $y >>>> [=, &$array]($x) => $array[] = $x + $y >>>> >>>> And of course it does have downsides: >>>> >>>> - Symbol soup (it uses a lot of symbols) >>>> - A minor BC break. Empty arrays which are invoked as functions are >>>> currently guaranteed to be errors at runtime and would have a new >>>> valid meaning. Here's an example from inside an array literal: >>>> >>>> // error at runtime previously >>>> [ []($x) => $x ] >>>> // now an array with one item which is a closure that returns >>>> its parameter >>>> >>>> Sara pointed out that we'd need to keep a leading `=` or `&` in the >>>> array to disambiguate from our array closure form. >>>> >>>> Overall I'd prefer 1 or 5. What do you guys think? >>> I think 5 is terrible from a readability point of view. As you said it: >>> "symbol soup". >> Do you think having ==> instead of => would make it less of a >> symbolic soup? > If something is already symbol soup how does adding another symbol > make it less so? > For me it was about using a symbol that is not used for other things like arrays. Kind of a new ingredience to the soup ;-) Not sure at all about the syntax, but going from Sara's example earlier. 1. [[]($x)=> $x] a bit similar to [($x)=> $x] vs 2. [[]($x)==> $x] less similar to [($x)=> $x] 2 has in my eyes less soup factor... Cheers //Björn