On Fri, 21 Feb 2014 19:42:41 -0000, Jesse Phillips <jesse.k.phillip...@gmail.com> wrote:
On Friday, 21 February 2014 at 16:41:00 UTC, Regan Heath wrote:
and make this possible too:

        foreach([index, ]value; range) { }

I understand the user interface is simple, but you created 3 statements about how it could be achieved and work/not work with the existing setup. Each have their positives and negatives, it would not make sense to "just choose one" and hope it all works out.

if AA is changed to a double[string], then your value loop iterates on keys and your key loop iterates on values.

No, I was actually suggesting a change here, the compiler would use type matching not ordering to assign the variables. So because 'v' is a string, it is bound to the value not the key.

And string is the key, double[string] is not the same as string[double].

Also string[string], ambiguous yet common.

There are many things to consider when adding a feature, it is not good to ignore what can go wrong.

Yes.. something is not being communicated here. I addressed all this in the OP.

Thanks!  Ok, so how is this working?  ahh, ok I think I get it.
enumerate returns a range, whose values are Tuples of index/value where value is also a tuple so is flattened, and then the whole lot is flattened into the foreach.

Sounds like you understand it, seams foreach will flatten all tuples.

I don't think this affects what I actually want to change, we can have:

        foreach(index, value; range) { }

and still flatten tuples into value, you would simply have to provide one extra variable to get an index.

Make sense?

Yes, but I'm saying we don't need it because

        foreach(index, value; range.enumerate) { }

is good enough. Not perfect, but good enough.

No, not good enough. This should just work, there is no good reason for it not to.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to