Good morning Rasmus, Thank you for your interest. This is just a proposal that I have tested and works. Of course, the final syntax can be different. Syntax is always a matter of taste :-)
> it is only useful in one limited type of trivial closure usage This trivial usage is actually the most common one. A single-return closure can be used for sorting, mapping, filtering, lifting, folding, comparing, validating, formatting, lazy-loading etc. which cover the majority of the tasks a PHP programmer does everyday. The popular LINQ library is just an example of the power of this kind of closures. The only case that these closures are not useful is asynchronous (event-driven) programming. However, PHP is single threaded and usually delegates the user interface to javascript, and therefore, two major needs for asynchronous programming are eliminated. > In PHP we try really hard not to invent new unfamiliar syntax. I have done some research before posting and it seems that the proposed syntax is not at all uncommon. For example, here is the same comparer written in a variety of languages: Proposed for PHP: | $x , $y |=> $x - $y C#: ( x , y )=> x - y Haskell: \ x y -> x - y Python: lambda x y: x - y OCaml, F#: fun x y -> x - y StandardML: fn x y => x - y There are many similarities here. In all of the above examples, there is no return and no curly brackets. In addition, all expressions begin with a token and separate the arguments from the returning expression with another token. Kind regards, Lazare INEPOLOGLOU Ingénieur Logiciel 2011/8/4 Rasmus Lerdorf <ras...@lerdorf.com> > 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. > > 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. > > -Rasmus >