On 6/5/2017 6:17 PM, Larry Garfield wrote: > 3 > 4 > 1. > > 2 is not even worth considering and I'd almost prefer not having arrow > functions if their syntax is going to be that self-defeating. > > I also see no reason to include both by-value and by-reference binding > Arrow functions are for trivially simple cases where the extra ceremony > of an anonymous function is a waste. If you need to do something > non-trivial, use a full-on anonymous function as we already support. > > I want to reiterate that, from a user-POV, arrow functions are barely > functions. It's a case for applying an expression to a set. In most > cases I don't "think about it" as a function in the first place. > > $y = 2; > array_map($arr, ($x)=> $x*$y); > > While I know that implementation-wise $x * 2 gets wrapped into a > function, that's not really how I'm mentally thinking about it. I'm > thinking of it more like a single line in a foreach. In my head, it's > an expression, not a function. If I needed to be "thinking about it > like a function", I'd use a more function-esque syntax. > > The extra complication of multiple binding styles to think about are > just that: extra complication. If I care, then I should be using an > anonymous function whose use() syntax already lets me control that case. > > I wonder if "Arrow functions" is even a misleading name for the feature, > in terms of how it should be used. > > --Larry Garfield >
I agree with Larry here. Another thing that would be great to have is a universal syntax that we can expand to cover methods at a later point too. Ceylon has that available everywhere, and it is nice for writing simple methods. final class SomeEnum { private $v; private __construct(string $v) => $this->v = $v; public static Foo() => new static('FOO'); public static Bar() => new static('BAR'); } Could someone explain me again what the problem with the simple fat-arrow and normal parenthesis is? Cannot find it anymore (too many messages in too many thread I guess). I would guess that it has to do with the arbitrary look-ahead that is required to check for the fat arrow before the lexer knows that this is a short closure and not some parenthesis that simply groups something. Wouldn't it be possible to go for the pipes then? I mean, pipes without an expression to the left are not valid right now, and they most probably will never be. Union types might require them, but they are not lonely there too. Hence: || 42 function () { return 42; } |$a, $b| $a + $b function () { return $a + $b; } References and use should be easy to add: |$a| |&$b| $b += $a function ($a) use (&$b) { return ($b += $a); } This syntax does not translate nicely to method though: public static Foo|| new static('FOO'); Looks kind 'a weird and now we have something on the lhs of the pipes that looks very much like a union type. We could still go for the fat arrow syntax here, even if the pipes are used for short closures. The two features are not the same after all. -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature