RE: [PHP-DEV] Inline Lambda Functions
| From: | John Crenshaw | Date: | Wed, 29 Jun 2011 17:03:24 +0000 |
| Subject: | RE: [PHP-DEV] Inline Lambda Functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53671@lists.php.net to get a copy of this message | ||
> Instead of this.....
>
> array_filter($source, function($x){ return $x < 5; });
>
> Being able to do this..... (or something like it).
>
> array_filter($source, $x => $x < 5);
This really isn't clear. Deciphering the intent of the code requires looking at all the
surrounding stuff, because it could mean something totally different in an array. In other words,
// This would be a lambda
array_filter($source, $x => $x < 5);
// This would not
array($source, $x => $x < 5);
// and this would not
call_user_func_array('array_filter', array($source, $x => $x < 5));
The fact that the syntax for an expression isn't portable in places where (so far) every other
expression has been, is a serious concern.
Additionally, the proposed syntax is unusable for functions with more than one line, making it
similar in badness to if statements without braces. IMO the current syntax for inline functions is
perfectly sufficient, even for the PLINQ example given earlier, and has massive advantages over this
one in terms of readability, affordance, flexibility, and language clarity.
John Crenshaw
Priacta, Inc.