On Wed, Sep 2, 2015 at 3:48 PM, Rowan Collins <rowan.coll...@gmail.com> wrote: > Amendment 1. Only allow the single-expression form of the short syntax; full > function bodies must be declared with the existing function(){ ... } syntax. > This gives a clearer distinction between how the two syntaxes can be used. > I'm down with that. Short syntax works best when it's concise. If my callback needs to do more, I tend to prefer writing the method elsewhere, and naming the variable its in according to what it does. Yay readability!
> Amendment 2. Make the ~> operator non-associative, so that lambdas returning > lambdas would need an extra pair of brackets making the nesting explicit. To > take one of Anthony's examples: > > function partial(callable $cb) { > return $left ~> ( $right ~> $cb($left, $right) ); > } > > It's now at least clearer that there are two different anonymous functions > here, even if it's not entirely clear what they're trying to achieve... > Again, I support this. I use parenthesis generously so that there's never a doubt. And because we got ternary's associativity wrong. > Amendment 3. Make the parentheses around the argument list mandatory so that > (if Amendment 1 is also adopted) there is only a single variant of the > syntax, namely "( param list ) ~> expression". > I like it for consistency, but I will say that 80% of my short lambda uses are callbacks for map and filter, which are single arg callbacks (when used without keys), so I do seldom see parens used at all.... in fact, I think that just convinced me why we need to be consistent. Imagine someone not understanding why adding a second parameter breaks their short lamba declaration... > Amendment 4. Consider a syntax involving an explicit "use". This one > requires a bit more exploration, but maybe something like: > ( $a use $b ) ~> $a + $b > or: > ( $a ) use ( $b ) ~> $a + $b > Not a fan of this one at all. Maybe it's my Javascript showing through, but I like the automatic capture. Not that I'd cry foul if it were required though. Good short lambdas are short short lambdas, so their use statements would be small anyway. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php