iteration over a string

bearophile bearophileHUGS at lycos.com
Tue May 28 14:20:08 PDT 2013


Timothee Cour:

> 3A)
> why not having an Enumerate(R) containing a single 'opApply' 
> public method,

Unfortunately opApply doesn't not work well with all the other 
range-based functions.
Also that Enumerate code is for illustrative purposes, it's not 
meant to be good library code.


> 3B)
> requiring one to use 'myrange.enumerate' for inputRanges and 
> 'myrange' in
> other cases is bad for generic programming and user time.

Generic programming must know if you are iterating only on items 
or on index-item pairs. As Python Zen says, explicit is better 
than implicit.


> This is a very
> frequent idiom that should just work out of the box. Language 
> is more
> orthogonal and less surprising in this case.

Yet Python designers have preferred to use enumerate instead of 
messing with the Python for.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list