RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Sep 8 17:42:26 PDT 2008
Sean Kelly wrote:
> 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.
That's great to hear, but I should warn you that moving from arrays to
"the lowest range that will do" is not quite easy. Think of std::rotate
for example.
>> 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 :-)
Wait until you see the generators! An efficient generator of Fibonacci
numbers in one line...
auto fib = generate!("a[0] + a[1]")(1, 1);
I'm so excited I can hardly stand myself. :o)
Andrei
More information about the Digitalmars-d-announce
mailing list