iteration over a string
Timothee Cour
thelastmammoth at gmail.com
Tue May 28 13:46:29 PDT 2013
Thanks for the enumerate pointer.
3A)
why not having an Enumerate(R) containing a single 'opApply' public method,
to avoid returning tuples in 'front()'
3B)
requiring one to use 'myrange.enumerate' for inputRanges and 'myrange' in
other cases is bad for generic programming and user time. This is a very
frequent idiom that should just work out of the box. Language is more
orthogonal and less surprising in this case. That being said, enumerate
still has its value (eg for foreach (i, k, v;
associativeArray.byPair.enumerate()) )
3C)
if no-one can find a concrete argument why it would cause clashing /
confusion, I will file an enhancement request for it (dip sounds overkill)
On Tue, May 28, 2013 at 10:31 AM, bearophile <bearophileHUGS at lycos.com>wrote:
> Timothee Cour:
>
>
> Where do you think it can cause clashing?
>>
>
> I don't know.
>
> But my solution is to introduce a simple "enumerate" range:
> http://d.puremagic.com/issues/**show_bug.cgi?id=5550<http://d.puremagic.com/issues/show_bug.cgi?id=5550>
>
> So if you have a range and you don't need indexes you use:
>
> foreach (item; myrange) {}
>
> If you also want an index:
>
> foreach (index, item; myrange.enumerate) {}
>
> This is the solution used by Python, it's clean, and it doesn't make the
> foreach syntax & compiler more complex. Later the compiler should optimize
> this idiom well.
>
> Bye,
> bearophile
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130528/92da4573/attachment.html>
More information about the Digitalmars-d-learn
mailing list