Maybe we don't need foreach ;-)
Bill Baxter
dnewsgroup at billbaxter.com
Mon Oct 30 21:53:21 PST 2006
Reiner Pope wrote:
> I don't see much reason to change the syntax here, since:
> - it provides no generalizations/abstractions
It generalizes 'for'.
> - it only saves 4 keys of typing
It's more about saving a keyword in the grammar than saving typing.
> - it isn't easier to read; perhaps even *harder* (you don't know
> whether it is a custom iterator or a 'normal' for loop)
Yeh, that's sort of true, but 90% of regular for loops have a ++ or --
or += or .next() in them at the end that make them pretty easy to
recognize as regular for loops. Any for loop that doesn't fit that
pattern already takes some scrutiny to figure out.
> - Walter's right: it could increase bugs, such as:
>
> for (char[] key, char[] value; aggregate)
>
> which looks similar to
>
> for (char[] key; char[] value; aggregate)
That'd be a syntax error. You cannot declare variables in the second
clause of a standard for-loop. You can only have an Expression there.
But yeh, I'm sure you can cook up some example where you change one
comma to a semicolon and both are legal.
Anyway, the real answer is trailing delegates. This wasn't a serious
proposal for change, more just musing on what could have been. foreach
didn't really have to be a keyword, I don't think, that's the only
observation I was trying to make.
--bb
More information about the Digitalmars-d
mailing list