Re: [RFC]Discuss] Syntax for Arrow Functions

From: Date: Thu, 08 Jun 2017 16:28:40 +0000
Subject: Re: [RFC]Discuss] Syntax for Arrow Functions
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to internals+get-99458@lists.php.net to get a copy of this message
> 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? On Thu, Jun 8, 2017 at 5:56 PM, Fleshgrinder <php@fleshgrinder.com> wrote: > On 6/7/2017 9:45 PM, Rasmus Schultz wrote: > >> the fn($a, $b) => $a + $b ** $c syntax suddenly > >> becomes an acceptable > > compromise. > > > > I have to second that. > > > > I might even propose to shorten it from "fn" to just "f" - the > > resulting > > syntax then resembles a mathematical predicate :-) > > > > I really like your thinking here. +1 for just f. > > I am not sure why we would require the fat arrow anymore. We most > probably want some symbol there to separate the return type constraint > from the body, but it could be a single symbol instead of two: > > f($x) = $x^3 > f(int $x): int = $x^3 > > We could go full math here! :) > > -- > Richard "Fleshgrinder" Fussenegger > >

« previous php.internals (#99458) next »