Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99275 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63030 invoked from network); 30 May 2017 18:36:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 18:36:09 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.47 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.47 mail-it0-f47.google.com Received: from [209.85.214.47] ([209.85.214.47:37606] helo=mail-it0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/13-43873-79BBD295 for ; Tue, 30 May 2017 14:36:09 -0400 Received: by mail-it0-f47.google.com with SMTP id g126so46783917ith.0 for ; Tue, 30 May 2017 11:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0szMettfuRNJTcoYhcXOSZ0dCjt47U2XIRotLukT43Y=; b=gL9RD6zzzIud5+ewSIQ7PyutswtK7c6fXNyCzhgcyo0MVrod4vQdsaoxs1fnViaNrF rLOtsbLimjHi5/RthJs3HCvqk7ubFGHdAW1QLadvXST2Mcvc7aMTbmNm3/k37QHdVdN2 /G5sGghBsxAoKlkBvHl2xDDIS/m51PQIe0qSQUlCaN25EtCeaqvy7AV7eXQAZiVYN09Y x/60kHRFGxBoMnhAb3TLsBUyVjGpjaWCaqRy+XyW8bewnRPAg4433MOP0ol5/qaDdLd7 cwWWmH+1RmoQuuQf8kxDMc/5dmXdekfBs9onmC+KSzGuuFLi1EeF5UEaghBT8S5wQyYd GAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0szMettfuRNJTcoYhcXOSZ0dCjt47U2XIRotLukT43Y=; b=uQinIMavhQqKQXfhB+8KUz5rMgdnkrLmTV1QZElJoy9Gn6yu6vRpEkGCuyECkgo1Uc O3IvY/f8m1uqUQyxXhxqqawaYFM0JK9r9vbpA6Vbc5PwGm2QiO6mzRDHKjPM8q+9ojKD NFxOCAsU/+wfp442pIn3ULDbwEj83E9XwDw8HMARIhrdqCFzZawbrJzkBWg/iDBZ56M1 tdDtqXxvpEmyP5aSygqLTGh8t3uDn5LNYwNncdlegflbF+d20ot1jawpqej+sF+tkq3t gHEp7puCqXZMr+BQRQwRFsszQrgcaEtxUuhsnbIPtQFntWc2vMvrB4XA4C0kf4TkGQXQ 7sjA== X-Gm-Message-State: AODbwcCfaF0fpRTuDicWhdo1muBSOhf/+xiNeHT13MunIyRtBcWNVSdY lliiNxtTsddhmpDts699YH/nO5tASQ== X-Received: by 10.36.17.197 with SMTP id 188mr3578652itf.28.1496169364786; Tue, 30 May 2017 11:36:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.12.158 with HTTP; Tue, 30 May 2017 11:36:04 -0700 (PDT) In-Reply-To: References: <301641f7-57fc-7a9c-90da-4fd4e4126cff@telia.com> Date: Tue, 30 May 2017 20:36:04 +0200 Message-ID: To: Levi Morrison Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , PHP internals Content-Type: multipart/alternative; boundary="001a11437efe8314fc0550c21371" Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: nikita.ppv@gmail.com (Nikita Popov) --001a11437efe8314fc0550c21371 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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) =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 say > >> 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> migh= t > > 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 extension. However [$var1, $var2]() is not necessarily failing right now, it may be a valid array callable. Nikita --001a11437efe8314fc0550c21371--