Lambda syntax, etc
grauzone
none at example.net
Mon Feb 9 07:05:52 PST 2009
bearophile wrote:
> grauzone Wrote:
>> I really like this one, but I'd prefer something like
>> > auto r = find(range, {a -> a.Weight > 100});
>>
>> Note the -> instead of the =>, to avoid any ambiguities with the
>> comparison operator.
>
> Let's play more; then what do you think about (all the following are legal):
>
> auto r1 = range.find({ x -> x.weight > 100 });
> auto r2 = range.find({ x :: return x.weight > 100; });
> auto r3 = range.find({ x :: stmt1(x); stmt2; });
> auto r4 = range.find({ x, y :: stmt1; return foo(y); });
>
> I like those enough, they seem balanced, uniform, not too much error-prone, they have only one visual chunk, short enough and easy to write :-)
Agreed.
Especially I like that "normal" and "functional" uses have distinct
syntax. This is much better than the proposal, to allow omission of the
return statement, and to return last value of the last expression
statement instead (like in (x){if(x>0) x+=1; x;}).
> Note that this syntax:
> auto r1 = range.find({ x -> x.weight > 100 });
> using my dlibs is equivalent to the following:
> auto r1 = range.find((ArrayType1!(typeof(range)) x) { return x.weight > 100; });
>
> Bye,
> bearophile
More information about the Digitalmars-d
mailing list