Re: [RFC] Arrow functions / short closures
| From: | Rowan Collins | Date: | Thu, 14 Mar 2019 14:54:32 +0000 |
| Subject: | Re: [RFC] Arrow functions / short closures | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104714@lists.php.net to get a copy of this message | ||
On Thu, 14 Mar 2019 at 14:12, Benjamin Morel <benjamin.morel@gmail.com>
wrote:
> This makes me thinking, has this syntax been considered?
>
> ($x) => { $x * $y }
>
> Nested:
>
> ($x) => { ($y) => { $x * $y } }
>
Wouldn't this have all the same parser problems as the RFC discusses?
The problem, as I understand it, is not avoiding ambiguity, it's avoiding
lookahead. If you write:
$foo = [ ($x) => { $x } ];
$bar = [ ($x) => $x ];
The parser has already consumed " [ ($x) =>" before it can decide if each
($x) is an array key or a closure signature. It's parseable, but only using
one of the workarounds described in the RFC.
If I'm understanding the RFC correctly, the only way to avoid that is to
have closures *start* differently from other valid constructs, because then
the parser doesn't need to recurse / backtrack / etc.
Regards,
--
Rowan Collins
[IMSoP]