odd syntax for foreach

Oskar Linde olREM at OVEnada.kth.se
Sat Aug 19 16:05:53 PDT 2006


BCS wrote:

> from: http://www.digitalmars.com/d/statement.html#foreach
> 
> <bnf>
> ForeachStatement:
> foreach (ForeachTypeList; Expression) Statement
> 
> ForeachTypeList:
> ForeachType
> ForeachType , ForeachTypeList
> </bnf>
> 
> Based on this the following is syntacticly correct.
> 
> void main()
> {
> char[] foo;
> foreach(i,j,k;foo)
> {}
> }
> 
> In fact it gives the error
> 
>     foreach.d(5): cannot infer type for j

Which is a correct error message.

> 
> which tells you nothing of much use. The following syntax looks more
> reasonable to me.
> 
> <bnf>
> ForeachTypeList:
> ForeachType
> ForeachType , ForeachType
> </bnf>

Why? How would you then handle more than two variable foreach loops?
foreach(i,j,k,l,m;foo) is a valid syntax given a foo with an opApply taking
a 5 argument delegate.

/Oskar



More information about the Digitalmars-d-bugs mailing list