Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64578 invoked from network); 30 May 2017 18:43:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 18:43:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.43 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.43 mail-it0-f43.google.com Received: from [209.85.214.43] ([209.85.214.43:37352] helo=mail-it0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/73-43873-65DBD295 for ; Tue, 30 May 2017 14:43:34 -0400 Received: by mail-it0-f43.google.com with SMTP id g126so46903122ith.0 for ; Tue, 30 May 2017 11:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=JTLGv6do7vPt7vnIT68BHAyMufnfGHvZtcau9P55rqc=; b=hchSOwh7si40BXq87BI65eNbVaOvqN6FlJZVhAHLJmoNOw6JkSSx/5s7OaKaX2D5w1 qmcVymv5QK6AUxxjSZBTf7jU4thLIuYltuBmuKH64K86xM7Amv2ielj0hkmtaYTWfBzi 7RQzCY5RlJUvW3u36vOAaeXmZ92ePDxjjLlB5bwIhykREZovxsThxgozShYieWYQsVxb dAM9rYBjBBPRjW3cuh76j3tPbgxCXTlrMqQ6pmNfXipylAmdMLFENnkCVBaAeMt/SdJG mg+VM52NpidlQw83m542UnqKgXZmc6CAH78v8kalwBnfs796AewuQU3imQSwKiKXSrcv nWBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=JTLGv6do7vPt7vnIT68BHAyMufnfGHvZtcau9P55rqc=; b=kAoI4asBEzbWCegoCX7Y/Ct63+Gxr52G5WvjnjQLi130WXfCmTxsSg1DZ8zbK2K9G0 eZr33mBy5b/NGAXg+8alQdaFnBOaSLdhIU5FjAByQJg4GEDQC2JLv/89DIgKcZQ5LaQQ K5Nl2jW/jndkszpG0udAl/cpb4+7DjPAXzjDXwkx3mZMB7XU2g6xizorwPXBu8BExHec PS9XUksupj6r2svSDgbcW63iayhHMp60DCcgTg4+mfHnwVHG7dp3vfbpJcPRN+tkVf1j 57LUa3FAa9AqRvdMVoddY8E2Dx5NqiY1OSX7dyPUyWiYEErpA72JVQoh+yQaCRt9TFC5 XggQ== X-Gm-Message-State: AODbwcDPDpn3BX/geTCs43H/L+/hh12JgZAggHsFroIgcKw2VB+Dx0nB TI3f7rCKm6hFihLdpouYVyhPbCJQXg== X-Received: by 10.36.131.137 with SMTP id d131mr3460285ite.113.1496169811736; Tue, 30 May 2017 11:43:31 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.107.12.159 with HTTP; Tue, 30 May 2017 11:43:31 -0700 (PDT) In-Reply-To: References: <301641f7-57fc-7a9c-90da-4fd4e4126cff@telia.com> Date: Tue, 30 May 2017 12:43:31 -0600 X-Google-Sender-Auth: 6Jo9BnG8u2RdFj23cWxbkUX2Whc Message-ID: To: Nikita Popov Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: levim@php.net (Levi Morrison) On Tue, May 30, 2017 at 12:36 PM, Nikita Popov wrote= : > On Tue, May 30, 2017 at 8:24 PM, Levi Morrison wrote: >> >> On Tue, May 30, 2017 at 12:16 PM, Bj=C3=B6rn Larsson >> wrote: >> > Den 2017-05-30 kl. 19:58, skrev Levi Morrison: >> >> >> >> 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) =3D> expr >> >> 2. function(params) =3D> expr >> >> >> >> 3. (params) =3D=3D> expr >> >> 4. (params) =3D> 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) =3D> expr // binds no values >> >> [=3D](params) =3D> expr // binds by value >> >> [&](params) =3D> 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) =3D> $array[] =3D $x + $y >> >> [=3D, &$array]($x) =3D> $array[] =3D $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 ar= e >> >> 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) =3D> $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 `=3D` or `&` in the >> >> array to disambiguate from our array closure form. >> >> >> >> Overall I'd prefer 1 or 5. What do you guys think? >> >> >> >> >> >> [1]: I'm pretty sure it can be done but until it's done I can't sa= y >> >> so confidently because sometimes there are things lurking in our >> >> grammar I forget about. >> >> >> > As I said in the old thread, option 5 with =3D=3D> instead of =3D> mig= ht >> > be an option. I think that would mitigate the minor BC break. >> > >> > r//Bj=C3=B6rn >> >> The compatibility issue is with `[](params)` is that it is currently >> an empty array literal that will be invoked; this is guaranteed to be >> an error at runtime so it is unlikely to cause much trouble. A >> trailing `=3D=3D>` would not help here. > > > You mentioned ability to explicitly specify binding as a possible extensi= on. > However > > [$var1, $var2]() > > is not necessarily failing right now, it may be a valid array callable. > > Nikita As already mentioned we must maintain a leading `=3D` or `&`: [=3D, $var1, $var2]() [=3D, $var1, $var2]() Sorry if that was unclear.