Rust switches to external iteration

Timon Gehr timon.gehr at gmx.ch
Thu Jul 4 08:07:05 PDT 2013


On 07/04/2013 03:42 PM, Andrei Alexandrescu wrote:
> On 7/4/13 1:18 AM, Timon Gehr wrote:
>> On 07/04/2013 07:04 AM, Andrei Alexandrescu wrote:
>>> Evidence we've done the right thing by emphasizing ranges instead of
>>> opApply.
>>>
>>> http://www.reddit.com/r/programming/comments/1hl2qr/rust_07_released/
>>> https://mail.mozilla.org/pipermail/rust-dev/2013-June/004599.html
>>>
>>> Andrei
>>
>> Well, probably, but implementing ranges is still too tedious.
>> It is very likely that rust is going to fix that.
>
> Let's see.
>
>> It should be as simple as:
>>
>> auto map(alias a,R)(R r){
>>     foreach(x;r)
>>         yield a(x);
>> }
>
> Nonono. This gives you an input range.

(Note: I was stating a requirement on simplicity.)

I haven't specified that it will give you an input range. If the 
programmer can figure out the length etc. the compiler will often be 
able to do so as well. Maybe it's too much magic to make yield just work 
though.

Another possibility is to implement a DSEL in a library, but all my 
experiments in this direction pretty much fail quite early because DMD 
does not know how to deal with moderately complex analysis dependencies 
(yet?), and has gotten a lot worse recently. I think this issue needs 
more attention. DMD makes it seem legitimate by spitting out 'forward 
reference errors' whenever its rather poor heuristic fails. Are there 
plans for fixing that? (I have ideas and a proof-of-concept 
implementation that will go open source soon. Incidentally it is 
currently locked to DMD 2.060 because of the aforementioned regressions.)

> The current map() gives a range of the same category as the range passed.

I'm pretty well aware of that. :o)

> This is a major issue with
> yield. It does make it easy to implement input ranges, but I'm glad we
> did not build with it.
>
> Andrei




More information about the Digitalmars-d mailing list