www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feasibility of std.range and std.algorithm in D 1.0

reply Brian Palmer <d brian.codekitchen.net> writes:
I'm really excited about where std.range is headed, it feels like a
fundamentally better concept to me than STL iterators. I also do a lot of
Haskell, so the similarities I see there are very exciting. I feel fortunate in
that I and some of my co-workers get to use D 1.0 for work, but it's apparent
that it will be a very long time (in software terms) before we can switch to
2.0. And I'm perfectly OK with this, a lot of very, very good stuff is going
into 2.0 and I don't want it rushed.

Last night I started playing with the idea of doing a partial back-port of
std.range to D 1.0. After hacking on it for a few hours, I came up with
something that, from the end-user's standpoint, is very similar. It only works
in the newest dmd and in ldc, because of the need for partial IFTI. For
instance, this example from the ddoc works without change:

assert(equal(take(5, cycle([1, 2][])), [ 1, 2, 1, 2, 1 ][]));

So far I've implemented take, drop, cycle, chain, map, filter, inPlace and
find. However implementing a Range is more difficult than in 2.0, and
performance suffers somewhat. There are two main reasons for this: no ref
functions (which I've always thought a bizarre oversight), and no foreach range
support. Both could be implemented in a backwards-compatible way for 1.0, but
as I understand it the official stance is only bug fixes in 1.0 going forward.
So is there any chance at all of having these changes implemented? Even if not,
does this port interest anybody else? We aren't really satisfied with the
container/iterator libraries available for 1.0 so we'll likely pursue this
route.

The git repo for the code isn't public yet, so I've uploaded a snapshot zip for
the curious and/or bored. Be warned, late-night hacky code ahead.

http://www.codekitchen.net/ranges_and_algorithms.zip
Jan 30 2009
parent reply Bill Baxter <wbaxter gmail.com> writes:
On Sat, Jan 31, 2009 at 2:20 AM, Brian Palmer <d brian.codekitchen.net> wro=
te:
 Last night I started playing with the idea of doing a partial back-port o=
f std.range to D 1.0. After hacking on it for a few hours, I came up with s= omething that, from the end-user's standpoint, is very similar. It only wor= ks in the newest dmd and in ldc, because of the need for partial IFTI. For = instance, this example from the ddoc works without change:
 assert(equal(take(5, cycle([1, 2][])), [ 1, 2, 1, 2, 1 ][]));

 So far I've implemented take, drop, cycle, chain, map, filter, inPlace an=
d find. However implementing a Range is more difficult than in 2.0, and per= formance suffers somewhat. There are two main reasons for this: no ref func= tions (which I've always thought a bizarre oversight), and no foreach range= support. Both could be implemented in a backwards-compatible way for 1.0, = but as I understand it the official stance is only bug fixes in 1.0 going f= orward. So is there any chance at all of having these changes implemented? = Even if not, does this port interest anybody else? We aren't really satisfi= ed with the container/iterator libraries available for 1.0 so we'll likely = pursue this route.
 The git repo for the code isn't public yet, so I've uploaded a snapshot z=
ip for the curious and/or bored. Be warned, late-night hacky code ahead.
 http://www.codekitchen.net/ranges_and_algorithms.zip
It would be great if you would contribute this to the std2 project, which is an effort to backport phobos2 to D1. http://www.dsource.org/projects/std2 --bb
Jan 30 2009
parent reply Brian Palmer <d brian.codekitchen.net> writes:
Bill Baxter Wrote:
 
 It would be great if you would contribute this to the std2 project,
 which is an effort to backport phobos2 to D1.
 http://www.dsource.org/projects/std2
 
 --bb
Certainly, I've released it all into the public domain and once it's further along and cleaned up a bit, I'd be happy to submit it. I was aware of the std2 project but I was under the impression it had been abandoned, from reading the message on its wiki. Is that not the case?
Jan 30 2009
parent Bill Baxter <wbaxter gmail.com> writes:
On Sat, Jan 31, 2009 at 4:20 AM, Brian Palmer <d brian.codekitchen.net> wro=
te:
 Bill Baxter Wrote:
 It would be great if you would contribute this to the std2 project,
 which is an effort to backport phobos2 to D1.
 http://www.dsource.org/projects/std2

 --bb
Certainly, I've released it all into the public domain and once it's furt=
her along and cleaned up a bit, I'd be happy to submit it. I was aware of t= he std2 project but I was under the impression it had been abandoned, from = reading the message on its wiki. Is that not the case? It's not really abandoned, just new development kinda stopped when I hit the partial IFTI brick wall. I still use it. Especially std2.conv and std2.getopt. Now that partial IFTI is in D1, the development can start up again. The only problem I have now is the slowness of the recent compiler release. Compiles are sometimes very very slow with it. If you want check-in access to the repo, let me know. --bb
Jan 30 2009