Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104704 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25123 invoked from network); 14 Mar 2019 02:10:48 -0000 Received: from unknown (HELO v-smtpout3.han.skanova.net) (81.236.60.156) by pb1.pair.com with SMTP; 14 Mar 2019 02:10:48 -0000 Received: from [192.168.7.8] ([213.64.245.126]) by cmsmtp with ESMTPA id 4CruhDgoHmfV04CruhN9QC; Thu, 14 Mar 2019 00:01:02 +0100 To: Nikita Popov References: Cc: PHP internals Message-ID: <955a8f0c-b2b3-854f-7360-dfa60bd6d292@telia.com> Date: Thu, 14 Mar 2019 00:01:02 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-CMAE-Envelope: MS4wfP6KR8prjUSpfolxXQCtd5AXQiCvjMNyez6cnJ+MswrsB89uCPTm5R6bOKuta6BE9rCMJKH520Uqy5GTv0JaP+y3XA0CyHEdMRkI7nvRAcwaPH/aPWaQ PkSqMJTqJx/NjH+g7rXzmGrcnN4xiGW2mdCsQ201bV6EMsd8Z9cJPBSVNmgoOJX2zxlHYKUfszpqAXs7jmFLbcI6XI2LRn5RKx7tBnLJU6rrO5lQFOWNc9hm Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2019-03-13 kl. 16:56, skrev Nikita Popov: > Hi internals, > > Motivated by the recent list comprehensions RFC, I think it's time we took > another look at short closures: > > https://wiki.php.net/rfc/arrow_functions_v2 > > This is based on a previous (withdrawn) proposal by Levi & Bob. It uses the > syntax > > fn($x) => $x * $multiplier > > and implicit by-value variable binding. This example is roughly equivalent > to: > > function($x) use($multiplier) { return $x * $multiplier; } > > The RFC contains a detailed discussion of syntax choices and binding modes. > > Regards, > Nikita Thanks for bringing this forward Nikita! I recall from the earlier discussions 2017 that also the lambda as a keyword was considered. I would like to bring that forward as one option, maybe less impact on existing code as a reserved keyword. An advantage of not having a keyword /prefix could be that for simple arrow functions no parenthesis is needed and readability is improved: $someDict->map(fn($v) => $v * 2)->filter(fn($v) => $v % 3); $someDict->map(\($v) => $v * 2)->filter(\($v) => $v % 3); $someDict->map(^($v) => $v * 2)->filter(^($v) => $v % 3); vs $someDict->map($v ==> $v * 2)->filter($v ==> $v % 3); $someDict->map($v ~> $v * 2)->filter($v ~> $v % 3); r//Björn L