www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Lambda syntax, etc

reply Kagamin <spam here.lot> writes:
grauzone Wrote:

 // syntax for lambda that contains a single expression, implicit return (this
is the most common case):
 auto r = find!(a => a.Weight > 100)(range);

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.

auto r = find(range, {a -> a.Weight <- 100}); :)
Feb 10 2009
parent reply bearophile <bearophileHUGS lycos.com> writes:
Kagamin:
 auto r = find(range, {a -> a.Weight <- 100});

Take a look at how the Fortress language manages spaces inside expressions. It can find a syntax error there, because the spacing is misleading. Bye, bearophile
Feb 10 2009
parent reply Kagamin <spam here.lot> writes:
bearophile Wrote:

 Kagamin:
 auto r = find(range, {a -> a.Weight <- 100});

Take a look at how the Fortress language manages spaces inside expressions. It can find a syntax error there, because the spacing is misleading.

There is no error here, since there's no <- operator, the construct is unabiguous, it just looks weird.
Feb 10 2009
next sibling parent Kagamin <spam here.lot> writes:
Kagamin Wrote:

 auto r = find(range, {a -> a.Weight <- 100});

Take a look at how the Fortress language manages spaces inside expressions. It can find a syntax error there, because the spacing is misleading.

There is no error here, since there's no <- operator, the construct is unabiguous, it just looks weird.

well, every construct can look weird in some environment.
Feb 10 2009
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
Kagamin:
 There is no error here, since there's no <- operator, the construct is
unabiguous, it just looks weird.

In Fortress the syntax of this expression is OK: x + 2 * 3 x + 2*3 This is a syntax error, because the spaces are misleading: x+2 * 3 Bye, bearophile
Feb 10 2009