Notes IV

Janice Caron caron800 at googlemail.com
Fri Jan 25 01:22:07 PST 2008


On Jan 25, 2008 9:08 AM, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> It's funny you should say that, because just today I was staring at a
> couple of foreaches that were giving me compiler errors and scratching
> my head.  Turns out I had written this:
>
>       foreach(i,ang, angles) {
>           ...
>       }
>
> Now maybe you can see right away what's wrong, but in my somewhat sleepy
> state and with my preferred ProggyTT programming font, I just didn't
> notice the missing pixel there.   It's much harder to mistake a comma
> for an 'in'.

There is a slight problem there, which is that "in" already has a
meaning, and one day "foreach" might understand it. As in:

    class C { /*...*/ }
    C[] array;
    foreach(in element; array)

meaning, the body of foreach may not modify any of C's member
variables. (Currently, foreach does not play nice with constancy, but
one might suppose this will be fixed in the future).



More information about the Digitalmars-d mailing list