foreach problem

BCS nothing at pathlink.com
Fri Jan 5 12:09:30 PST 2007


Dejan Lekic wrote:
> Mr/Mrs BCS,
> here is the part of documentation i maybe did not understand well:
> ----------------- snip ------------------
> ForeachStatement:
>     Foreach (ForeachTypeList; Aggregate) ScopeStatement
> 
> Foreach:
>     foreach
>     foreach_reverse
> 
> ForeachTypeList:
>     ForeachType
>     ForeachType , ForeachTypeList
> 
> ForeachType:
>     inout Type Identifier
>     Type Identifier
>     inout Identifier
>     Identifier
> ----------------- snip ------------------
> 
> If I understand this correctly, than simple code like the one in foreach_bug.d
> should work because 'arg' is clearly an 'Identifier' from the 'ForeachType' rule
> above.
> 
> I am posting foreach_bug.d again here:
> -- foreach_bug.d ---------8<------------------------------------------
> import std.stdio;
> 
> int main(char[][] args) {
>   char[] arg;
>   foreach (arg; args)  // <-- problem here
>     writefln(arg);
>   return 0;
> }

This is a case where D applies implicit typing rules to determine the 
type of a variable declaration. The Above syntax definition says that an 
identifier can be place at that point, it says nothing about what is 
done with it. In this case, the semantics cause it to be a variable 
deceleration.


More information about the Digitalmars-d-bugs mailing list