RFC on range design for D2

Sean Kelly sean at invisibleduck.org
Mon Sep 8 16:30:09 PDT 2008


Andrei Alexandrescu wrote:
...
> 
> After much thought and discussions among Walter, Bartosz and myself, I 
> defined a range design and reimplemented all of std.algorithm and much 
> of std.stdio in terms of ranges alone.

Yup.  This is why I implemented all of Tango's algorithms specifically 
for arrays from the start--slices represent a reasonable approximation 
of ranges, and this seems far preferable to the iterator approach of 
C++.  Glad to hear that this is what you've decided as well.

> This is quite a thorough test 
> because the algorithms are diverse and stress-test the expressiveness 
> and efficiency of the range design. Along the way I made the interesting 
> realization that certain union/difference operations are needed as 
> primitives for ranges. There are also a few bugs in the compiler and 
> some needed language enhancements (e.g. returning a reference from a 
> function); Walter is committed to implement them.

Very nice.  The inability to return a reference has been a thorn in my 
side for ages.

> I put together a short document for the range design. I definitely 
> missed about a million things and have been imprecise about another 
> million, so feedback would be highly appreciated. See:
> 
> http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.html

It seems workable from a 1000' view.  I'll have to try and apply the 
approach to some algorithms and see if anything comes up.  So far, 
dealing with bidirectional ranges seems a bit weird, but that's likely 
more related to the syntax (ie. 'pop') than anything.


Sean

P.S. This decision has interesting implications for D2+, given the 
functional tendencies already present in the language :-)


More information about the Digitalmars-d-announce mailing list