Re: An implementation of a short syntax for closures

From: Date: Thu, 04 Aug 2011 09:03:16 +0000
Subject: Re: An implementation of a short syntax for closures
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi all :-),

On 04/08/11 09:23, Rasmus Lerdorf wrote:
On 08/04/2011 12:08 AM, Lazare Inepologlou wrote:
$add = | $x |=> | $y : $x |=> $x+$y;
This does not seem to match the syntax of any language I know of so people are going to have a hard time figuring out what this does. It's not even clear that |=> is a new operator there due to the dangling |, which as you say conflicts with the regular | operator. Plus it is only useful in one limited type of trivial closure usage. This syntax reminds me the “block lambda syntax”, presented on the ECMAScript's wiki [1] about the future of ECMAScript6. It seems they tend to choose the “arrow function syntax” [2], which is more natural and more readable. You can found pros and cons on the wiki, along with a lot of use cases/examples (including rebinding this!).
For a quicker introduction to these two short syntaxes, I would suggest you to read the conference “FalsyValues” [3], from slide 31 to 36, recently given by Dmitry Soshnikov about the future of ECMAScript 6 (all the conference is a beauty, a must-read).
In PHP we try really hard not to invent new unfamiliar syntax. We try to stick with things that have some basis in either the existing syntax or in other popular languages that the average PHP developer might be exposed to. +1. It must be the result of a long reflection and we should get a large vote from the community before choosen one syntax.
Best regards. [1] <http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival> [2] <http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax> [3] <http://www.slideshare.net/dmitrysoshnikov/falsyvalues-dmitry-soshnikov-ecmascript-6> -- Ivan Enderlin Developer of Hoa Framework http://hoa.42/ or http://hoa-project.net/ Member of HTML and WebApps Working Group of W3C http://w3.org/

Thread (32 messages)

« previous php.internals (#54343) next »