Iterating over multiple collections in parallel

bearophile bearophileHUGS at lycos.com
Sat Jul 5 07:41:26 PDT 2008


Fawzi Mohamed:

> for i,a in enumerate([1,2,3].iterator()):

I may have lost you a bit here, anyway in real Python that code is:

for idx, el in enumerate([1, 2, 3]):
    print idx, el

> Using fibers, as in the nice example of downs it should also be 
> possible to convert automatically an opApply in a generator, so 
> technically it should be feasible, even if 500 cycles per conetext 
> switch, might be too much for some applications (tight loops).
> So in D one could have a something workable
> foreach(a,b,i;collectLoop([1,2,3],[2,3,7],Range(1,infinity))){
> ...
> }
> Implementation of it is left as exercice to the reader ;-)

In my libs there are zip() and azip() for something like that, but they don't use fibers yet... Once the fibers are added, the code can be made smart at compile-time, so it can use the current fast code when possible, and fibers when it must.

Bye,
bearophile



More information about the Digitalmars-d mailing list