Den 2017-05-30 kl. 04:48, skrev Levi Morrison:

On Mon, May 29, 2017 at 4:47 AM, Björn Larsson
<bjorn.x.lars...@telia.com> wrote:
Den 2017-04-05 kl. 23:57, skrev Levi Morrison:

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.
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.
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.
      [](params) => expr     // binds no values
      [=](params) => expr    // binds by value
      [&](params) => 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]

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 error

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.

Well, my preference would be for alternative 3. Not in favour of 2 & 4.
Nr 1 not so sure about and for nr 5, maybe tweak it to:
- [](params) ==> expr    // binds no values
- [=](params) ==> expr    // binds by value
- [&](params) ==> expr    // binds by reference

Leaving out [] could also be a default:
- (params) ==> expr    // binds no values

I presume then that the options discussed earlier "|params| => expr"
and "lamda(params) => expr" are of the table.

r//Björn Larsson

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to