On Wednesday, 20 July 2016 at 15:40:16 UTC, Lobelia Noakes wrote:
On Sunday, 17 July 2016 at 01:58:59 UTC, pineapple wrote:
On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote:
On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote:
actually, `foreach (v; rng)` looks like `foreach` is
*reusing* *existing* *variable*. most of the time you can
put `immutable` or something like that there to note that it
is not reusing (purely cosmetical thing), but sometimes you
cannot, and then `auto` is perfect candidate... but it is
not allowed. (sigh)
Chipping in my agreement. foreach(x; y) makes as much
syntactic sense as for(x = 0; x < y; x++) where x was not
previously defined. One does not expect something that does
not look like every other variable definition in the language
to be defining a new variable.
Furthermore, if foreach(int x; y) is legal then why isn't
foreach(auto x; y)?
By the way there's an error in the grammar:
ForeachTypeAttribute:
ref
TypeCtor
But BasicType also already includes TypeCtor. So a TypeCtor in
a foreach typelist is ? well hard to say, part of basic type or
part of ForeachTypeAttribute ?
It's a minor issue BTW. I think that everybody that would write a
D parser will skip parsing of TypeCtor in ForeachTypeAttribute
and rather consider them as part of the type. I'm not sure if it
can be completly removed from ForeachTypeAttribute...Does anyone
know ?