Re: Arrow function expressions in PHP

From: Date: Thu, 01 Oct 2015 15:16:08 +0000
Subject: Re: Arrow function expressions in PHP
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-88607@lists.php.net to get a copy of this message
On Thu, Oct 1, 2015 at 8:58 AM, Nikita Nefedov <inefedor@gmail.com> wrote: > > I don't think there was a dozen of different ideas, I could only find > those about lambda(arg-list; use-list; expression) and > variations of it > with different keywords and different return-type syntax. > I do understand that this is quite subjective, but neither this syntax nor > fn(arg-list; use-list) expression look obvious and easily > readable to me. > It doesn't look obvious because its new syntax. The first time I saw a for(var; bool; expr) I was totally confused, because I had only seen for var in range. But you know what? I looked at the docs and then knew how it worked, not that hard. > And one thing that makes auto capture much better choice than explicit > capture (as it've been said a couple of times already) is partial > application: > > $mul = fn($x) => fn($y) => fn($z) => $x * $y * $z; > > Looks simpler than: > > $mul = fn($x) => fn($y; $x) => fn($z; $x, $y) => $x * $y * $z; > > Yes it looks simpler, but if this is going to continue being the argument for auto-capturing can we at least get a real world example? I have never once in the wild seen a lambda that returns a lambda that returns a lambda, all using variables from the previous lamba(s). I'm fairly certain no one will invoke the overhead of a function call 3 times just to multiply 3 numbers together. Please give me a valid example if you want me to believe this to be a valid argument. There is no way in php that I know of to get access to a parent's scope, unless explicitly used which is only available on lambda/closures. Therefore, automatic closing of the variables is very much against the scoping rules of the language. It is totally unexpected for someone who has been using the language for many years.

« previous php.internals (#88607) next »