Re: [RFC][Discuss] Arrow Functions
| From: | Bob Weinand | Date: | Tue, 31 Jan 2017 21:44:05 +0000 |
| Subject: | Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98096@lists.php.net to get a copy of this message | ||
> Am 31.01.2017 um 19:41 schrieb Christoph M. Becker <cmbecker69@gmx.de>:
>
> On 31.01.2017 at 19:16, Michael Morris wrote:
>
>> On Tue, Jan 31, 2017 at 12:29 PM, Larry Garfield <larry@garfieldtech.com>
>> wrote:
>>
>>> My question is why there's no mention of HHVM short closures, or the
>>> previous RFC to take that approach. See:
>>>
>>> https://docs.hhvm.com/hack/lambdas/introduction
>>
>> For what it's worth I'd rather look at
>>
>> array_map( $x ==> $x + 1);
>>
>> than
>>
>> array_map( fn($x) => $x + 1 )
>>
>> Not to mention the former isn't a bc break.
>
> Neither is supposed to work, though. :)
>
> Anyhow, I'm not sure whether I'd prefer
>
> array_map($a, $b, $c ==> $a + $b + $c, $a1, $a2, $a3)
>
> over
>
> array_map(fn($a, $b, $c) => $a + $b + $c, $a1, $a2, $a3)
>
> or maybe
>
> array_map(fn $a, $b, $c => $a + $b + $c, $a1, $a2, $a3)
>
> Somehow, I tend to like a trailing keyword for better left-to-right
> readability.
>
> --
> Christoph M. Becker
The RFC states that we're needing some form of a prefix in order to avoid implementing gigantic
lexer hacks.
HHVM internally implements it by parsing some part of the syntax INSIDE the lexer and then emitting
a token before the first parameter to tell the parser where a short Closure begins.
Having a normal terminal symbol easily allows the parser to detect short Closures, without any
hacks.
It is just not a practical option from a technical point of view, and thus not worth even
considering.
Bob