On 30 May 2017 18:58:14 BST, Levi Morrison <le...@php.net> wrote:
>Internals,
>
>The previous discussion thread has died down significantly and so I'd
>like to start a new one to refocus. This message has some redundant
>information by design so people don't have to reference the other
>thread so much.
>
>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.

I was just pondering alternative approaches to stop the => token being 
ambiguous, and wondered if surrounding the whole expression with braces could 
work:

{ => $bound * 2 }
{ $a, $b => $a * $b }

I believe this eliminates the ambiguity with array notation, and is more 
concise than pretty much every alternative. I'm my opinion, grouping the 
arguments and body would make it more readable in context, as well.

The only potential difficulty with parsing would be that this would technically 
be valid:

if ( $test ) { $a => $a * 5 };

Because it means this:

if ( $test ) { function ($a) { return $a * 5; }; }

It's not ambiguous, but I don't know if this and similar constructs would cause 
problems with backtracking in the parser. Worst case, they could probably be 
defined as illegal, since it's pretty hard to construct a use case for such a 
thing.

Regards,

-- 
Rowan Collins
[IMSoP]

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

Reply via email to