Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99464 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9747 invoked from network); 8 Jun 2017 21:20:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2017 21:20:27 -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.156 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.156 v-smtpout3.han.skanova.net Received: from [81.236.60.156] ([81.236.60.156:54222] helo=v-smtpout3.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/79-27119-89FB9395 for ; Thu, 08 Jun 2017 17:20:26 -0400 Received: from [192.168.7.8] ([195.198.188.252]) by cmsmtp with SMTP id J4qrdnXjaARCaJ4qrdtFNG; Thu, 08 Jun 2017 23:20:22 +0200 To: Fleshgrinder References: <3F920987-38CB-42DD-888D-824430C36F14@gmail.com> <2f9e73c9-444a-11d0-459a-e261ea8a7080@telia.com> <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> <40dc6de9-7e05-e043-e8e3-9e93409be2bd@fleshgrinder.com> <1db8ba6d-3020-e32a-8005-3e3072803ea5@fleshgrinder.com> Cc: Rasmus Schultz , PHP internals Message-ID: <622fce97-0ae4-dbe9-5396-f846476b42f7@telia.com> Date: Thu, 8 Jun 2017 23:20:20 +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: <1db8ba6d-3020-e32a-8005-3e3072803ea5@fleshgrinder.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: sv X-CMAE-Envelope: MS4wfH67Q2SnmraXkiOMfbeFUEnCWDyLqcOUSB6ZKZB1zzySz65Zw8eqPQRq5d5SjBJwo+svh3VI8ZUzBHhK9zTWo+rC2QAnZLc6qlrceqUBgju42HFCPV4G Qm5Hmn4CGAtxiPZDL7pzf+46Ryym7nP+OsfCan5uwQc7btq47wlKDa/0uRG7HtgvbHzSrDzMV2oQVOMcu98XBWxFVSgRcAIUijzOlCM1MYL8C3xNgrthTn4M iL5Olz3HH0m8yyWAqG0BpQ== 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-08 kl. 19:21, skrev Fleshgrinder: > On 6/8/2017 6:28 PM, Rasmus Schultz wrote: >>> it could be a single symbol instead of two >> even if this can be done without parser ambiguity, it suffers from visual >> ambiguity with the assignment operator. >> >> consider what this would look like if the expression itself uses the >> assignment operator... >> >> f($x) = $y = $y + $x; >> >> versus something like: >> >> f($x) => $y = $y + $x; >> >> even that is visually ambiguous when used in arrays though: >> >> $a = [ >> "foo" => f($x) => $y = $y + $x, >> ]; >> >> also unreadable. >> >> even if the parser can cope, I think we need some other symbol that isn't >> visually ambiguous when used in these contexts? >> > Absolutely, yes. > > One thing that could work is a combination of colon and equal sign with > an optional type in between: > > f($x, &$y):= $y = $y + $x > f($x, &$y): int = $y = $y + $x > > Still, kind of ambiguous if used with a type. Earlier I used the greater > than sign only: > > f($x, $y)> $x > $y > f($x, $y): bool > $x > $y > > As we can clearly see, also not optimal. A thing that should work is a > hyphen greater than: > > f(object $o)->$o->property > > Looks weird without proper spacing, but with proper spacing ... > > f(object $o) -> $o->property > > ... it looks fine, imho. Of course, we still have the other options that > were mentioned earlier already: > > f ~> 42 // bad on some keyboard layouts > f ==> 42 // I personally do not like this option > > Another possibility is to use a keyword. This would definitely avoid > symbol soup and help visual recognition: > > f do 42 > f($x) do $x^3 > f($x, &$y) do $y = $y + $x > > However, I am very unsure about this option to be honest. > > I'd say my choice here is `~>` but I'm on a US layout, second is `->`. > Note that the latter is used in Java, Elixier, Erlang, Haskell, Julia, > OCaml, F#, and probably others. > Well, one reason ~> came up in the earlier RFC was that ==> was not seen as quite the best. I liked the tilde option then and do it now. For me that sits on a nordic keyboard layout, I need to use Alt-gr both for $ and ~, extra space for tilde though. So using tilde is no big hassle ;-) So not all liked the syntax then, but there was other things making that RFC fail. If type hinting had been included and variable binding had been slightly different, I think it might have passed. r//Björn