digitalmars.D.bugs - odd syntax for foreach
- BCS (24/24) Aug 19 2006 from: http://www.digitalmars.com/d/statement.html#foreach
- Oskar Linde (6/38) Aug 19 2006 Why? How would you then handle more than two variable foreach loops?
- BCS (7/45) Aug 19 2006 I known of nowhere that says that anthing but the 1 and 2 argument forms...
- Oskar Linde (7/56) Aug 20 2006 It tells you exactly what was wrong to the compiler. It didn't find a wa...
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 tells you nothing of much use. The following syntax looks more reasonable to me. <bnf> ForeachTypeList: ForeachType ForeachType , ForeachType </bnf>
Aug 19 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 jWhich 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
Aug 19 2006
Oskar Linde wrote:BCS wrote:but it tells you nothing about what is wrong.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 jWhich is a correct error message.I known of nowhere that says that anthing but the 1 and 2 argument forms of the opApply are even valid. I haven't tried it though. Looking at the sepc, it looks like it might be allowed, but it dosn't actualy say so. Whatever the case, the docs need a little work here and the error message gives nothing usefull other than the line numberwhich 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
Aug 19 2006
BCS wrote:Oskar Linde wrote:It tells you exactly what was wrong to the compiler. It didn't find a way to infer the type for j. Such error messages are often better than if the compiler tries to guess what you intended.BCS wrote:but it tells you nothing about what is wrong.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 jWhich is a correct error message.It is allowed and works very well.I known of nowhere that says that anthing but the 1 and 2 argument forms of the opApply are even valid. I haven't tried it though. Looking at the sepc, it looks like it might be allowed, but it dosn't actualy say so.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. /OskarWhatever the case, the docs need a little work here and the error message gives nothing usefull other than the line numberThe correct file? The correct line number? And you are still complaining? ;) /Oskar
Aug 20 2006