> ... ( $x ) => $x + 1 for example would be ambiguous if used in an array definition, but is
> otherwise the best in terms of readability.
> ... people wanted an easy way to grep for function declarations
A new and unique operator (like the |=> I have proposed) is a solution
that works because:
1. A lambda expression can be part of other expressions, like arrays.
Therefore, we cannot reuse =>, or ->.
2. Multiple lambda expressions can be chained. The operator must have
very low precedence and it be right associative.
3. Lambdas should be grep-able.
For those who would like to try other syntaxes that could work in PHP,
I suggest a simple and creative way to approach this. All we need is 3
operators:
OP_A args OP_B lexical_vars OP_C expr
Operator OP_C ought to have the above properties (unique, low
precedence, right associative). On the other hand there are no
restrictions about OP_A and OP_B and we can reuse existing ones as
long as they don't conflict and they look nice.
:-)
Lazare INEPOLOGLOU
Ingénieur Logiciel
2011/8/4 Johannes Schlüter <[email protected]>:
> On Thu, 2011-08-04 at 21:18 +1000, Ryan McCue wrote:
>> Lazare Inepologlou wrote:
>> > 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 :-)
>>
>> As much as I love the idea, I have to agree that using | doesn't really
>> make sense here and actually makes the readability worse, IMO. However,
>> I can't really think of a better operator. ( $x ) => $x + 1 for example
>> would be ambiguous if used in an array definition, but is otherwise the
>> best in terms of readability.
>
> If you go there you can also allow more complex statements and re-use
> symbols used to group statements, using a syntax like
>
> ( $x ) { $x + 1; }
>
> Oh wait - now we've reached a point which was mentioned in this thread
> already "allow to drop the function keyword".
>
> Back when I proposed to drop "function" a key argument was that people
> wanted an easy way to grep for function declarations. I accepted the
> validity of that concern and think this might be a case here, too. The
> difference of these few characters is not that much but the keyword
> gives a clear guidance what's going on, else you might end up with a
> long list of random characters next to each other ...
>
> johannes
>
>
>