Template instantiation syntax

bearophile bearophileHUGS at lycos.com
Sat Oct 11 16:48:00 PDT 2008


Andrei Alexandrescu:
> bearophile wrote:
> > foreach (i, x in something) {...}
> > Instead of the current more error-prone:
> > foreach (i, x; something) {...}
> 
> Both can be done with a CFG.

Recently I have explained here why the syntax (i, x; something) is error prone, and other people have told me that they agree that sometimes that syntax leads to bugs like (i, x, something) (and the error message isn't much clear).

I have received an answer, maybe from Walter, that syntax (i, x in something) can't be accepted because "in" is already taken to tell the key presence inside an associative array (while not being yet usable to scan for presence of items into a normal array), so it "can't" be used inside the foreach syntax too...

So probably it's not a problem of grammar, but of successive stages of the compilation. The net result for the programmer is the same, this time the D compiler is rigid and doesn't allow for a more readable/less error-prone syntax.

Bye,
bearophile



More information about the Digitalmars-d mailing list