Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99304 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66239 invoked from network); 31 May 2017 20:46:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 May 2017 20:46:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=ilija.tovilo@me.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ilija.tovilo@me.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain me.com designates 17.142.194.252 as permitted sender) X-PHP-List-Original-Sender: ilija.tovilo@me.com X-Host-Fingerprint: 17.142.194.252 pv33p00im-asmtp003.me.com Received: from [17.142.194.252] ([17.142.194.252:25848] helo=pv33p00im-asmtp003.me.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/10-43873-F9B2F295 for ; Wed, 31 May 2017 16:46:24 -0400 Received: from process-dkim-sign-daemon.pv33p00im-asmtp003.me.com by pv33p00im-asmtp003.me.com (Oracle Communications Messaging Server 7.0.5.38.0 64bit (built Feb 26 2016)) id <0OQU000003O5ZQ00@pv33p00im-asmtp003.me.com> for internals@lists.php.net; Wed, 31 May 2017 20:45:54 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=4d515a; t=1496263554; bh=jGUVq/B69IoQG8OSZqSi7QSJuCNcxaQTdx3iddn1oxw=; h=Date:From:To:Message-id:Subject:MIME-version:Content-type; b=YurjzKZnMQwz9JODnmyziSRbk4Mvf4d4TuZmGzCwrIZhHHVgNkM/UGINiHdHLaV2G 5Ne46GIDz0J7CnJkyI9vEJjK6VUYa+aB4s2ID0EvdFdvPj8TwTA1Xr8OO9G0PbdIQe GK0NZca99cWYJn334Xh5J+yywDCDsurkrTnagXB7iTXqBZqJwhIjB60htLewNg4Wk5 /Pe9sW458ZvYIuRmXv8QoJg66l7hVGufcJFYG1Oi5Np/zmb6niR12MiDNVbXFoi46R VGSLH6k32GRuq5WCFr6VphNBmmsVujn4fa8oPS/q6lkL9/pZRoQsAELBbk7dP7O963 aLjP27BoqxVbw== Received: from icloud.com ([127.0.0.1]) by pv33p00im-asmtp003.me.com (Oracle Communications Messaging Server 7.0.5.38.0 64bit (built Feb 26 2016)) with ESMTPSA id <0OQU000614CCIP30@pv33p00im-asmtp003.me.com>; Wed, 31 May 2017 20:45:51 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-31_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1034 suspectscore=74 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1701120000 definitions=main-1705310376 Date: Wed, 31 May 2017 22:40:24 +0200 To: internals , Levi Morrison , Rowan Collins Message-ID: In-reply-to: References: X-Readdle-Message-ID: c38d31ef-3ffb-4b0e-b6b8-09696971af5a@Spark MIME-version: 1.0 Content-type: multipart/alternative; boundary=592f2b7a_3a230482_854b Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: ilija.tovilo@me.com --592f2b7a_3a230482_854b Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline My preferences: 1, 3, 4, 5, (big void), =C2=A02. I actually like 4 the most but I get that that might not be practical if = it leads to unexpected behaviour. I can=E2=80=99t think of a scenario where capturing by reference would be= helpful in a single line closure. 5 just adds additional complexity with= no additional benefit IMHO. Also, in response to=C2=A0Rowan, a Ruby-style syntax should be possible t= hough: =7B=7Cparam=7C expr=7D Only caveat is that the =7C=7C would be required if there are no paramete= rs: =7B=7C=7C expr=7D Levi has mentioned this one before. You could even omit the braces here. Ilija On 30 May 2017, 19:58 +0200, 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) =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. > =5B=5D(params) =3D> expr // binds no values > =5B=3D=5D(params) =3D> expr // binds by value > =5B&=5D(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=5B1=5D > - Can be extended to allow explicit binding of variables: > // all equivalent > // y is bound by value, array by reference > =5B&, =24y=5D(=24x) =3D> =24array=5B=5D =3D =24x + =24y > =5B=3D, &=24array=5D(=24x) =3D> =24array=5B=5D =3D =24x + =24y > > 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 > =5B =5B=5D(=24x) =3D> =24x =5D > // 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 =60=3D=60 or =60&=60 = in the > array to disambiguate from our array closure form. > > Overall I'd prefer 1 or 5. What do you guys think=3F > > > =5B1=5D: 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. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --592f2b7a_3a230482_854b--