lazy thoughts

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jan 12 20:31:15 PST 2009


Daniel Keep wrote:
> Andrei Alexandrescu wrote:
>> Bill Baxter wrote:
>>> [snip]
>>>
>>> Another commonly used func from Python is zip().  Not sure if that one
>>> is doable in D because it relies heavily on Python's tuples to work,
>>> but in Python it offers a very clean solution to iterating over
>>> several lists at once.
>>>      for xy in zip([1,2,3],[4,5,6]):
>>>         # xy gets sequence of tuples (1,4), (2,5), (3,6)
>>>
>>>      for x,y in zip([1,2,3],[4,5,6]):
>>>         # tuple split into x and y automaticallly
>> zip() is absolutely on the list.
> 
> How are you going to implement zip?  I tried writing a version ages ago,
> and the issue I ran into is that you cannot support any user-defined
> iterables with it.
> 
> The problem is that opApply uses inversion of control to do its work, so
> you can't run more than one opApply in lockstep unless you're using some
> form of threading.

opApply should be first dipped in tar, then dipped in feathers, and 
finally walked around town in a wooden cage. I think it's the least of 
all D in the D spirit. Abstractions that look cute and pretend there's 
no cost => ~D.

zip will be implemented with ranges and std.typecons.Tuple.

> In a more general note, this is all shaping up to be incredibly awesome;
> keep up the good work! :D

Thanks. Now I need to find the time to make nice on the promise... lest 
I get tarred and feathered myself :o).


Andrei



More information about the Digitalmars-d mailing list