On Mon, Jan 30, 2017 at 18:12 Andrea Faulds <a...@ajf.me> wrote:

> Hi Levi,
>
> Levi Morrison wrote:
> > Here is an example of an existing closure:
> >
> >     function ($x) use ($arr) {
> >         return $arr[$x];
> >     }
> >
> > This RFC proposes syntax and semantics to simplify this common usage to:
> >
> >     fn($x) => $arr[$x]
> >
>
> Is it necessary to introduce a new keyword, fn?
>
> I think you'd get a similar benefit from:
>
>      function($x) => $arr[$x]
>
> Likewise, is it necessary to restrict auto-capture to the => syntax?
> Couldn't we allow the following?
>
>      function ($x) {
>          return $arr[$x];
>      }
>

This looks too similar to the current syntax, just ignoring the use()
statement. I would add a concurance that => syntax is slightly awkward when
used within an array element

$a = [
  'func' => fn($x) => Class::method($x),
];

But I'm not overly certain of a different syntax to handle this.

I would support expanding to function over fn, to make it more
readable/keep the same reserved word. (Although not too certain to the
complexity in the parser)

Otherwise +1, I like this.

--
Dave

Reply via email to