Re: [RFC][Discuss] Arrow Functions
| From: | Björn Larsson | Date: | Tue, 30 May 2017 08:30:02 +0000 |
| Subject: | Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99258@lists.php.net to get a copy of this message | ||
Den 2017-05-30 kl. 04:48, skrev Levi Morrison:
On Mon, May 29, 2017 at 4:47 AM, Björn Larsson <bjorn.x.larsson@telia.com> wrote:Nr 1 not so sure about and for nr 5, maybe tweak it to:Den 2017-04-05 kl. 23:57, skrev Levi Morrison:Based on the discussion there are a few different syntax choices that we probably just need to vote between. 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 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.Any hope this one will make it into PHP 7.2? Of course maybe it's prudent to have some more discussion and then it's 7.3. Regards //Björn Larsson PS If there is some writing needed for the RFC itself maybe I could assist, need to get an account & karma first though.Any plans to go with this for 7.2?I have been working on this RFC a bit in the last two weeks and intend to start voting within the next week.[](params) => expr // binds no values [=](params) => expr // binds by value [&](params) => expr // binds by referenceIt 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] And of course it does have downsides: - Symbols soup (it uses a lot of symbols) - A minor BC break; the following piece which is guaranteed to be an error would now have meaning:[](optional params) // previously an errorOverall 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. Well, my preference would be for alternative 3. Not in favour of 2 & 4.
- [](params) ==> expr // binds no values - [=](params) ==> expr // binds by value - [&](params) ==> expr // binds by referenceLeaving out [] could also be a default:
- (params) ==> expr // binds no valuesI presume then that the options discussed earlier "|params| => expr" and "lamda(params) => expr" are of the table. r//Björn Larsson