Re: [RFC]Discuss] Syntax for Arrow Functions
| From: | Theodore Brown | Date: | Thu, 01 Jun 2017 16:58:08 +0000 |
| Subject: | Re: [RFC]Discuss] Syntax for Arrow Functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99311@lists.php.net to get a copy of this message | ||
On Tuesday, May 30, 2017 at 12:58 PM, Levi Morrison wrote:
> 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
> 5.
> [](params) => expr // binds no values
> [=](params) => expr // binds by value
> [&](params) => expr // binds by reference
As a userland developer, I've been waiting/hoping for short arrow
functions for a long time!
Option 3 seems like the most obvious choice, since that's the
same syntax Hack uses. Would it be very difficult to implement the
parser changes necessary for this syntax? Or is there some other
downside to a more powerful grammar/parser (e.g. worse performance)?
If option 3 isn't viable, my next preference would be option 1.
Presumably the drawback of a new symbol is that it might break
existing code using
fn as the name of a class or function.
However, using a new symbol would arguably enable more readable
code than the other options.
Option 2 is not only lengthy, but it also could be confusing
since it reuses the function symbol for something that isn't
a normal function.
Option 5 seems overly complex and hard to read.
Whether option 1, 2, or 3 is used, to me it seems that capturing by
reference would be the most useful and intuitive behavior. It's
intuitive since implicit capture makes it feel like all the captured
variables are in the same scope.