Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99476 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32776 invoked from network); 10 Jun 2017 12:43:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jun 2017 12:43:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.218 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.218 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.218] ([81.169.146.218:13459] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/F4-01593-A89EB395 for ; Sat, 10 Jun 2017 08:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1497098631; l=7765; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=V5ogIE07LqT63azbhIJMyjkMEDEPQw6qFp/FOW+kCU8=; b=APlS1HS7WhSHmPpVuwnxS6l/vT1pYHSsAh37JCgJli0IZ9zu0WwEEpPIYUwZoieg1F OlJ/VjiIaFH7GIsB40WLGftQsfwselkOrO/UwLSJZSkt2/fZ4YOzV0SZUFLcJ+P9Re+k 0rogDASLVz7r9V0y7YPGU/4MyZy9JeKFymACs= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtPntX9w== X-RZG-CLASS-ID: mo00 Received: by mail-ot0-f180.google.com with SMTP id a2so49733495oth.2 for ; Sat, 10 Jun 2017 05:43:50 -0700 (PDT) X-Gm-Message-State: AKS2vOzCFRlxkbvmIR7ES5KrMl7+OzTqiSIwCH309eLDNas5QWpTPAt9 ILbie+5IrtWIigUA3ogB+W7MArOJRw== X-Received: by 10.157.47.195 with SMTP id b3mr21862607otd.78.1497098630037; Sat, 10 Jun 2017 05:43:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.176.133 with HTTP; Sat, 10 Jun 2017 05:43:49 -0700 (PDT) In-Reply-To: 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> <04c92b98-0fb2-6288-f22e-ebcc45cfecac@telia.com> Date: Sat, 10 Jun 2017 14:43:49 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Stephen Reay Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , Sara Golemon , Rowan Collins , PHP internals Content-Type: multipart/alternative; boundary="001a113db9e4098b2505519a70e7" Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: me@kelunik.com (Niklas Keller) --001a113db9e4098b2505519a70e7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-06-10 11:09 GMT+02:00 Stephen Reay : > > > On 10 Jun 2017, at 15:19, Bj=C3=B6rn Larsson > wrote: > > > > 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=C3=B6rn Larsson < > bjorn.x.larsson@telia.com> > >>> wrote: > >>>> If I take the liberty in using the example above on our option list: > >>>> 1. $someDict->map(fn($v) =3D> $v * 2)->filter(fn($v) =3D> $v % 3); > >>>> 2. $someDict->map(function($v) =3D> $v * 2)->filter(function($v) =3D= > $v % > >>> 3); > >>>> 3. $someDict->map($v =3D=3D> $v * 2)->filter($v =3D=3D> $v % 3); > >>>> 4. $someDict->map(($v) =3D> $v * 2)->filter(($v) =3D> $v % 3); = // > >>>> Ambiguous > >>>> 5. $someDict->map([]($v) =3D> $v * 2)->filter([]($v) =3D> $v % 3); > >>>> > >>>> Old proposals: > >>>> 6. $someDict->map($v ~> $v * 2)->filter($v ~> $v % 3); > >>>> 7. $someDict->map(lambda($v) =3D> $v * 2)->filter(lambda($v) =3D> $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 =3D=3D>, but I think that shows a little bit of why the Hac= kLang > >>> team decided the messy lexer was worth the clearer syntax. > >> > >> Another possible syntax (dunno whether this has already been suggested > >> on-list): > >> > >> $function =3D { $x =3D> 2 * $x }; > >> $function =3D { ($x) =3D> 2 * $x }; > >> $function =3D | $x =3D> 2 * $x |; > >> $function =3D | ($x) =3D> 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 =3D> $v * 2})->filter({$v =3D> $v % 3}); > > 9. $someDict->map(|$v =3D> $v * 2|)->filter(|$v =3D> $v % 3|); > > > > I also find that parenthesis makes it cluttered. > > $someDict->map({($v) =3D> $v * 2})->filter({($v) =3D> $v % 3}); > > > > Cheers //Bj=C3=B6rn > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > I find it quite odd that people are claiming paren=E2=80=99s around 0 arg= uments is > =E2=80=98clutter=E2=80=99, but curly braces or pipes around the entire th= ing is somehow not > clutter. While I understand there are small differences like implicit > return and automatic capturing, having such wildly different syntax to a > regular still doesn=E2=80=99t make much sense to me. The difference is that `{ ... }` or `| ... |` is required to be unambiguous, otherwise it conflicts with other parser rules. Regards, Niklas --001a113db9e4098b2505519a70e7--