Is str ~ regex the root of all evil, or the leaf of all good?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Feb 19 10:14:07 PST 2009


Jarrett Billingsley wrote:
> The point I'm making here is it doesn't matter whether it uses 'in' or
> ';' or ':' or '(%)#*@' to separate the loop indices from the container
> expression, because there will always be people who feel that another
> syntax is better or more natural.  Instead of arguing over minute
> details like this, let's worry about the important things, like the
> semantics of foreach loops.

I agree. One thing that ranges still don't address is binding multiple 
values to them:

foreach (a, b, c; range) statement

Steve promoted the idea that the code above is translated to:

{
     T1 a;
     T2 b;
     T3 c;
     auto __r = range;
     for (; !__r.empty; __r.next)
     {
         __r.head(a, b, c);
         statement
     }
}

It's a good idea, and I'd favor e.g. a discussion around it as opposed 
to one on whether ";" is the proper separator.

Oh, there was another wrinkle: if you have a container, how do you 
obtain a range from it? I suggested container.all, but then people said 
that's a step backwards from opApply. I think [] should be used for 
accessing all of a range. Something that is already a range simply 
returns "this" from opSlice(). So the code above with this other 
proposal tucked in becomes:

{
     T1 a;
     T2 b;
     T3 c;
     auto __r = range[];
     for (; !__r.empty; __r.next)
     {
         __r.head(a, b, c);
         statement
     }
}


Andrei



More information about the Digitalmars-d mailing list