Re: [RFC] Short syntax for anonymous functions
| From: | Lars Strojny | Date: | Tue, 19 Feb 2013 13:56:15 +0000 |
| Subject: | Re: [RFC] Short syntax for anonymous functions | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65952@lists.php.net to get a copy of this message | ||
Hi Marcello,
Am 19.02.2013 um 14:51 schrieb Marcello Duarte <mduarte@inviqa.com>:
> Thanks for the feedback. I get most people here don't appreciate the value of the feature.
>
> I can understand that If you haven't tried to write a tool like capistrano, rspec, chef,
> puppet, etc, etc in PHP you probably won't see much value in implementing such things.
>
> On 19 Feb 2013, at 13:19, Derick Rethans wrote:
>> On Tue, 19 Feb 2013, Marcello Duarte wrote:
>>
>>> Inspired by Sara, here is another RFC, I finally got around to draft:
>>>
>>>
>>> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
I don’t like the syntax, but the proposal in general. If you compare PHPs syntax to various
others, it is indeed clumsy.
Python:
map(lambda v: v * 2, [1, 2, 3])
Ruby:
[1, 2, 3].map{|x| x * 2}
Scala:
List(1, 2, 3).map((x: Int) => x * 2)
PHP:
array_map(function ($x) {return $x * 2;}, [1, 2, 3]);
So even a statically typed language like Scala is shorter and better to read. A good improvement
would be implicit return and getting rid of the function keyword.
array_map(($x): $x * 2;, [1, 2, 3]);
But this RFC should come with a patch, otherwise we are discussing things that aren’t necessarily
easy to implement.
cu,
Lars