Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99474 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21779 invoked from network); 10 Jun 2017 08:19:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jun 2017 08:19:14 -0000 Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain telia.com from 81.236.60.154 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.154 v-smtpout1.han.skanova.net Received: from [81.236.60.154] ([81.236.60.154:37936] helo=v-smtpout1.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/14-01593-08BAB395 for ; Sat, 10 Jun 2017 04:19:13 -0400 Received: from [192.168.7.8] ([195.198.188.252]) by cmsmtp with SMTP id Jbbwdn1NfPPY2JbbwdolpM; Sat, 10 Jun 2017 10:19:08 +0200 To: Niklas Keller , Sara Golemon Cc: Rowan Collins , PHP internals References: <4077c099-2247-c3c1-7dee-02a6b25f8586@fleshgrinder.com> <559b73f7-c40f-e593-f0e1-51b56210d7cb@telia.com> <2053A608-6B66-42FB-A6D7-7CC64E94DA6A@koalephant.com> <4FBDE643-1EBC-485A-A39F-7E28C5D4807A@koalephant.com> <034f3ebf-95b8-a7cf-1279-77c7cf0424d7@gmail.com> <46143e7c-ef75-7c05-eaa9-98c8f3b405f1@telia.com> Message-ID: <04c92b98-0fb2-6288-f22e-ebcc45cfecac@telia.com> Date: Sat, 10 Jun 2017 10:19:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: sv X-CMAE-Envelope: MS4wfPHUzOucraQBT3AUrIWFcR38xnVXWtIB5FgsZPTfYSOm/gaePKLwcr68aizfJ+KW29RANkRSV4WFQBGU2zFd4qVY2mlHrfxNacM+Qj/MJsw2BHpOJUxI uu6Qqv69V7wquWrw+2ABLCA2RDKT/t4Qyopu2QYfsD+C05fqQVNAISd6SHJ99Kzh81e0XOr/Xn+i+t3eaG0clw1DiBQVA8ub/2ZIpV18gzCVyVQFQlIP2VYF 9sG6dzXFSgGeKlaGWImkNdq/EqK+2JY9xUi73y71dJ8= Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2017-06-09 kl. 22:00, skrev Niklas Keller: > 2017-06-09 15:44 GMT+02:00 Sara Golemon : > >> On Fri, Jun 9, 2017 at 7:23 AM, Björn Larsson >> wrote: >>> If I take the liberty in using the example above on our option list: >>> 1. $someDict->map(fn($v) => $v * 2)->filter(fn($v) => $v % 3); >>> 2. $someDict->map(function($v) => $v * 2)->filter(function($v) => $v % >> 3); >>> 3. $someDict->map($v ==> $v * 2)->filter($v ==> $v % 3); >>> 4. $someDict->map(($v) => $v * 2)->filter(($v) => $v % 3); // >>> Ambiguous >>> 5. $someDict->map([]($v) => $v * 2)->filter([]($v) => $v % 3); >>> >>> Old proposals: >>> 6. $someDict->map($v ~> $v * 2)->filter($v ~> $v % 3); >>> 7. $someDict->map(lambda($v) => $v * 2)->filter(lambda($v) => $v % 3); >>> >> Something else which really pops in these examples is the effect of >> not needing to use parentheses when embedding a single-arg short >> lambda. 3 and 6 in your list read cleaner to me (due to the lack of >> parenthesis clutter). Sadly ~> has the same hacky implementation >> issues as ==>, but I think that shows a little bit of why the HackLang >> team decided the messy lexer was worth the clearer syntax. > > Another possible syntax (dunno whether this has already been suggested > on-list): > > $function = { $x => 2 * $x }; > $function = { ($x) => 2 * $x }; > $function = | $x => 2 * $x |; > $function = | ($x) => 2 * $x |; > > Nikita and Levi prefer it with parenthesis, I prefer it without, because I > think it's unnecessary clutter. > > A reason to use | ... | instead of { ... } would be to allow future object > literals. > Applying that to Sara's example becomes: 8. $someDict->map({$v => $v * 2})->filter({$v => $v % 3}); 9. $someDict->map(|$v => $v * 2|)->filter(|$v => $v % 3|); I also find that parenthesis makes it cluttered. $someDict->map({($v) => $v * 2})->filter({($v) => $v % 3}); Cheers //Björn