Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99274 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61096 invoked from network); 30 May 2017 18:24:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 18:24:19 -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.48 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.48 mail-it0-f48.google.com Received: from [209.85.214.48] ([209.85.214.48:37197] helo=mail-it0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/B2-43873-2D8BD295 for ; Tue, 30 May 2017 14:24:19 -0400 Received: by mail-it0-f48.google.com with SMTP id g126so46594426ith.0 for ; Tue, 30 May 2017 11:24:18 -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=iEoBq451wpHd4CjPSqUr7PSKS+hhRHquNvib1spkM28=; b=UC5Xy7x0lSocOgz10R5oZrdq+XtzGFZ8sa0u67t+MJjLOUPXlqtszHS3IbRMaHnz31 aIbtpFn8OJhT5ct+nsXwTA8Dm663AGmvvpNe9fB0l5A1+y0+L6PFm/+7yXFb/kO31zkE TpRUyLiFYGqxNlQWubO9mZ4vM2EqKHtFUodQCMveBrFCE3DR2vogWNuYNNLemXUSU5cK oFR0KIPMadwmVAo+zUBV1zPd3C168hxK8zzA6vMbzWQ4vauqqqOWK6pOVo7broTZqip/ XdHTYSO8O2IgaX+ZakXxG7oc44d149lT5DI6j7uBRd6dsJyq9/6q7tOYthhxyTUSHouA +1Eg== 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=iEoBq451wpHd4CjPSqUr7PSKS+hhRHquNvib1spkM28=; b=BeUsZKQ4MvlPRjaKQMCwatrLz1OPaATs1Xa4FqWli6prj+PyyxvQFbvGLq2EeylIR/ ZP51f/rc5dMkSnwMwtX5dmckdgizVicIE4I9492NH3UcFaNayDa2E7aYAA0r5kEtcUle pacq+ceNI/C+lDGJkSKb0PYogatGUS3D8DMNa9NiJaRI2Y37XkNLoZo6XzZeJqUXj2wG ehnOmyx5HwWOY0HKYU34F0NTnrCfrJQ441pnb1BxuFYZneu8pBOVUXVAlLVabAtp7fiY DNUPMgl2bPf4qtQcx46qTe2uhsq6IY/BbPIijIwy4wGzj17T9X7BpC8yVJugeP8jgmJz DcTg== X-Gm-Message-State: AODbwcD/LA68D09wYojArw3dJQ5gamCck5XQTfX5c6bC8MIfUavTlQON KDTpbo8vwjmHxWxIhNiWCb+7hKfn4Q== X-Received: by 10.36.5.196 with SMTP id 187mr3206847itl.29.1496168655880; Tue, 30 May 2017 11:24:15 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.107.12.159 with HTTP; Tue, 30 May 2017 11:24:15 -0700 (PDT) In-Reply-To: <301641f7-57fc-7a9c-90da-4fd4e4126cff@telia.com> References: <301641f7-57fc-7a9c-90da-4fd4e4126cff@telia.com> Date: Tue, 30 May 2017 12:24:15 -0600 X-Google-Sender-Auth: 9so06I_QSPy4F-xWc0qQH9xWSw8 Message-ID: To: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= Cc: 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: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> might > 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.