Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88653 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15763 invoked from network); 3 Oct 2015 14:38:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Oct 2015 14:38:59 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.137.24 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.137.24 dd15934.kasserver.com Received: from [85.13.137.24] ([85.13.137.24:48108] helo=dd15934.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/41-31315-088EF065 for ; Sat, 03 Oct 2015 10:38:57 -0400 Received: from dd15934.kasserver.com (dd0801.kasserver.com [85.13.143.205]) by dd15934.kasserver.com (Postfix) with ESMTPSA id 91D2B26068A; Sat, 3 Oct 2015 16:38:52 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SenderIP: 95.90.234.115 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: To: morrison.levi@gmail.com, pajousek@gmail.com Cc: internals@lists.php.net Message-ID: <20151003143852.91D2B26068A@dd15934.kasserver.com> Date: Sat, 3 Oct 2015 16:38:52 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC] Arrow Functions From: mails@thomasbley.de ("Thomas Bley") Pavel Kouřil wrote on 03.10.2015 10:06: > On Sat, Oct 3, 2015 at 1:17 AM, Levi Morrison wrote: >> I messaged the list about this feature before I had the RFC written up >> for it. The RFC[1] is slightly different from what I proposed in the >> previous thread, so please read the RFC to make sure you understand >> what is being proposed before replying here. >> >> Here's a small example: >> >> $y = 10; >> $result = array_map(function($x) => $x + $y, [1, 2, 3]); >> >> // $result is [11, 12, 13] >> >> Thanks for people who have participated in conversation so far, as >> well as those who participated in Bob's short closures proposal as >> well. >> >> [1]: https://wiki.php.net/rfc/arrow_functions >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Hello, > > thanks for another proposal on this feature. :) > > As I said in the previous e-mails, I'm not really fan of the > "function" prefix - because it has the same prefix as the "long > declarations". Just by removing the { } for =>, the autobinding also > goes into place* and also only one expression is allowed, but the > "beggining" stays the same (that being function ($x)). > > The function keyword also "collides" with the future scope with > multiple statements. > > function ($x) use ($a, $b, $c) { $z = foo($a, $b); return $c($z, $x); } > function ($x) => { $z = foo($a, $b); return $c($z, $x); } > > Now the possible confussion with the different scoping rules would be > even bigger, IMHO. (Disclaimer: I am huge fan of those autoimports and > think that without them, the RFC doesn't technically bring anything > important.) > > Also, I'm not a fan of the "fn" prefix, because then you would have > two ways of writing "function", and people would probably want being > able to use "fn" for named functions as well, bringing inconsistency > into language. Also, this would requiring making "fn" a reserved word, > breaking some applications - wouldn't it? > > Personally I'd prefer the \ prefix you also mention as possible in > your RFC. It's also AFAIK used to denote lamba expression in another > languages already, so it might be familiar for some developers? > > \(int $x) => $x * $y; > \() => foo() > \($x) => \($y) => \($z) > > Yeah, this looks pretty nice. > > Althought I'd honestly really prefer the Bob's syntax, but I > understand that you don't want to make some engine hacks to make it > working - but from userland developer's POV, that one was the best > (speaking as someone, who would use the syntax daily). > > -- > > Regards > Pavel Kouřil > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > I would prefer to keep the current syntax and just a different keyword for autobindung: function ($x) use ($a, $b, $c) { $z = foo($a, $b); return $c($z, $x); } function ($x) autobind|autouse|use_all|autoimport|etc. { $z = foo($a, $b); return $c($z, $x); } Regards Thomas