Well, we could take python's approach and use a syntax similar to this: array_filter($source, lambda $x: $x < 5);
array_map($source, lambda $x, $y: $x < $y); However, I would question the need. Pythonic lambdas cannot contain anything but expressions. Therefore they cannot have any meaningful side effects. While this is good, it also raises the question as to the need for it. PHP has first-class anonymous functions, something which python does not (it has local functions, or lambdas, but no true anonymous function, every non-lambda has a name). So the need in PHP for a lambda style construct is greater than PHP's. And what's the gain for PHP? A few less characters to type? I'm not sure that readability is gained, compare: array_filter($array, function($element) { return $element < 5; }); and array_filter($array, lambda $element: $element < 5); I feel the first is more readable at a glance. Anthony On Wed, Jun 29, 2011 at 1:03 PM, John Crenshaw <johncrens...@priacta.com> wrote: > >> 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. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php