Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99365 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7541 invoked from network); 5 Jun 2017 17:17:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2017 17:17:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.85 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.85 mx104.easyname.com Received: from [77.244.243.85] ([77.244.243.85:60350] helo=mx104.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/F1-27119-62295395 for ; Mon, 05 Jun 2017 13:17:28 -0400 Received: from cable-81-173-132-37.netcologne.de ([81.173.132.37] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1dHvd5-0003ac-HC; Mon, 05 Jun 2017 17:17:23 +0000 References: <6357d97c-3f2e-4cf8-cb1f-cb7f7ccccf7c@telia.com> <7eaef49b-bf60-9aa1-e812-8430164e3178@garfieldtech.com> To: php-internals , Larry Garfield Message-ID: Date: Mon, 5 Jun 2017 19:17:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <7eaef49b-bf60-9aa1-e812-8430164e3178@garfieldtech.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="COOSfHNvEkFFxxOIpS0O53Lxr2B4rvaRx" X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: php@fleshgrinder.com (Fleshgrinder) --COOSfHNvEkFFxxOIpS0O53Lxr2B4rvaRx Content-Type: multipart/mixed; boundary="LN5Q4IoedR00v2r43Jvig8PWSL9WaO0IQ"; protected-headers="v1" From: Fleshgrinder To: php-internals , Larry Garfield Message-ID: Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions References: <6357d97c-3f2e-4cf8-cb1f-cb7f7ccccf7c@telia.com> <7eaef49b-bf60-9aa1-e812-8430164e3178@garfieldtech.com> In-Reply-To: <7eaef49b-bf60-9aa1-e812-8430164e3178@garfieldtech.com> --LN5Q4IoedR00v2r43Jvig8PWSL9WaO0IQ Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 6/5/2017 6:17 PM, Larry Garfield wrote: > 3 > 4 > 1. >=20 > 2 is not even worth considering and I'd almost prefer not having arrow > functions if their syntax is going to be that self-defeating. >=20 > I also see no reason to include both by-value and by-reference binding = > Arrow functions are for trivially simple cases where the extra ceremony= > of an anonymous function is a waste. If you need to do something > non-trivial, use a full-on anonymous function as we already support. >=20 > I want to reiterate that, from a user-POV, arrow functions are barely > functions. It's a case for applying an expression to a set. In most > cases I don't "think about it" as a function in the first place. >=20 > $y =3D 2; > array_map($arr, ($x)=3D> $x*$y); >=20 > While I know that implementation-wise $x * 2 gets wrapped into a > function, that's not really how I'm mentally thinking about it. I'm > thinking of it more like a single line in a foreach. In my head, it's > an expression, not a function. If I needed to be "thinking about it > like a function", I'd use a more function-esque syntax. >=20 > The extra complication of multiple binding styles to think about are > just that: extra complication. If I care, then I should be using an > anonymous function whose use() syntax already lets me control that case= =2E >=20 > I wonder if "Arrow functions" is even a misleading name for the feature= , > in terms of how it should be used. >=20 > --Larry Garfield >=20 I agree with Larry here. Another thing that would be great to have is a universal syntax that we can expand to cover methods at a later point too. Ceylon has that available everywhere, and it is nice for writing simple methods. final class SomeEnum { private $v; private __construct(string $v) =3D> $this->v =3D $v; public static Foo() =3D> new static('FOO'); public static Bar() =3D> new static('BAR'); } Could someone explain me again what the problem with the simple fat-arrow and normal parenthesis is? Cannot find it anymore (too many messages in too many thread I guess). I would guess that it has to do with the arbitrary look-ahead that is required to check for the fat arrow before the lexer knows that this is a short closure and not some parenthesis that simply groups something. Wouldn't it be possible to go for the pipes then? I mean, pipes without an expression to the left are not valid right now, and they most probably will never be. Union types might require them, but they are not lonely there too. Hence: || 42 function () { return 42; } |$a, $b| $a + $b function () { return $a + $b; } References and use should be easy to add: |$a| |&$b| $b +=3D $a function ($a) use (&$b) { return ($b +=3D $a); } This syntax does not translate nicely to method though: public static Foo|| new static('FOO'); Looks kind 'a weird and now we have something on the lhs of the pipes that looks very much like a union type. We could still go for the fat arrow syntax here, even if the pipes are used for short closures. The two features are not the same after all. --=20 Richard "Fleshgrinder" Fussenegger --LN5Q4IoedR00v2r43Jvig8PWSL9WaO0IQ-- --COOSfHNvEkFFxxOIpS0O53Lxr2B4rvaRx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZNZIaAAoJEOKkKcqFPVVr5UgQALPy1g4OAhDU26lTzYnyGHtr XgKBE9QC906pe7bWHp639JJyhpqgyht8VDz6+7yJG3AMDpxLglK2QkiEKa7PRBEW FTaFohLZWk5MWD22s7j9/+A+LSMsAq3/FzX1NmGRPDwv8faBefhSrZTvz8XopUOh xoZHjkWEOX7OmFaybXZ0k5Q6USFU5GmxsXcvrjTM/n7X3CEuhUcoy8FjVHA5c0dn V7qiM/ijkQpbOCFe1M7fLPSfjfF4UEZ27XqhVR67+JKftsLl7UMtjugCOOWUcZvg /shutb5oBWAAdm+dP98MDXoXEsVCwnQZCrQMf6t7NggYE3j2cYS7vWB2EgN/c2Pn lhaPDD8TI8La7IPRTzgFRkz4VZoKdGZytOE5LkqvRQ3ZUcAwB9d4M0dEz/Z5uoEk dQU97NDez8heSuubEdBzrFrkFGmn4iX3EQl0kR+qUlXQ4SOnNT9u5OE9SQctlv3i kUP603NPdTeW2l6rPpYBX3LScbPKTStErGghcyJVeoK1/nM6miWHpAAXG51Ebiqm AKuFfX6z4Qo9GFM4FNF4ND+WGe9lnj6W82LArOnJcGRnINpQl1769FEBUHxHz17I L5NMBiPqUsACEqNmSnLd214MZn4GlSpDswnkk+mTG08ssPbjQ5KQvYS8X6IVHI0j 6oCbscMhJmx4JJFCDwMt =g1jC -----END PGP SIGNATURE----- --COOSfHNvEkFFxxOIpS0O53Lxr2B4rvaRx--