Breaking ";" rule with lambda functions
frame
frame86 at live.com
Mon Aug 1 17:01:33 UTC 2022
On Monday, 1 August 2022 at 14:15:31 UTC, pascal111 wrote:
> We all know the strange syntax of lambda function within filter
> algorithm like "auto r = chain(a, b).filter!(a => a > 0);". My
> note is, don't we break D rules by leaving ";" after lambda
> function syntax?!
>
> Many of D rules are taken from C, we know that, so a general
> basic rule is to put ";" after each statement, so the previous
> statement of filter should be "auto r = chain(a, b).filter!(a
> => a > 0;);"? Why D leaves ";" in this case?
In C ";" is a termination character, in D is more like to
separate statements.
The lexer wouldn't need ";" for most cases like JavaScript and
the expression syntax without ";" is better to read anyway.
However, the common settlement is to require a ";" where it makes
logical sense and where it's still needed for the lexer. So we
have this.
More information about the Digitalmars-d-learn
mailing list