Re: [PHP-DEV] [RFC] Arrow functions / short closures

This is only part of a thread. view whole thread
  104707
March 14, 2019 04:01 david.proweb@gmail.com (David Rodrigues)
I have two doubts about the RFC:

1. Your example with "($x) => $x" consider the use of "$x => $x", but not
specifically "($x) => $x". I mean: maybe it can accept "($x) => $x" but not
"$x => $x" because of the array conflict (as mentioned), and with that we
avoid to create a new keyword "fn". So parentheses is required.

2. I don't remember. haha

Em qua, 13 de mar de 2019 às 12:57, Nikita Popov ppv@gmail.com>
escreveu:

> Hi internals, > > Motivated by the recent list comprehensions RFC, I think it's time we took > another look at short closures: > > https://wiki.php.net/rfc/arrow_functions_v2 > > This is based on a previous (withdrawn) proposal by Levi & Bob. It uses the > syntax > > fn($x) => $x * $multiplier > > and implicit by-value variable binding. This example is roughly equivalent > to: > > function($x) use($multiplier) { return $x * $multiplier; } > > The RFC contains a detailed discussion of syntax choices and binding modes. > > Regards, > Nikita >
-- David Rodrigues
  104708
March 14, 2019 06:16 rowan.collins@gmail.com (Rowan Collins)
On 14 March 2019 04:01:54 GMT+00:00, David Rodrigues proweb@gmail.com> wrote:
>1. Your example with "($x) => $x" consider the use of "$x => $x", but >not >specifically "($x) => $x". I mean: maybe it can accept "($x) => $x" but >not >"$x => $x" because of the array conflict (as mentioned), and with that >we >avoid to create a new keyword "fn". So parentheses is required.
I don't think this helps, because you can put brackets around any expression, for precedence, and any expression can appear on the left of an array literal: $foo = [ ($bar + 1) * 2 => $baz ]; So the following, while redundant, is currently valid: $foo = [ ($bar) => $baz ]; Regards, -- Rowan Collins [IMSoP]
  104717
March 14, 2019 15:38 david.proweb@gmail.com (David Rodrigues)
Em qui, 14 de mar de 2019 às 03:17, Rowan Collins collins@gmail..com>
escreveu:

> I don't think this helps, because you can put brackets around any > expression, for precedence, and any expression can appear on the left of an > array literal: > > $foo = [ ($bar + 1) * 2 => $baz ]; > > So the following, while redundant, is currently valid: > > $foo = [ ($bar) => $baz ]; > Yeah, I don't think in that case. And maybe using [] instead of ()? For
instance: "[$x] => $x + 1". PHP don't supports and array as key, so maybe it will not causes any conflict. -- David Rodrigues