It is the year 2020: why should I use / learn D?

Steven Schveighoffer schveiguy at gmail.com
Wed Nov 14 18:46:00 UTC 2018


On 11/14/18 1:33 PM, jmh530 wrote:
> On Wednesday, 14 November 2018 at 17:33:27 UTC, Steven Schveighoffer wrote:
>> [snip]
>>
>> The solution is cursors -- a "range" of a single element, which points 
>> at that element. You can iterate it just like a range (it has front, 
>> popFront, and empty), but it's used basically to mark the location you 
>> are interested in.
>>
>> dcollections used cursors, which I found much nicer. [snip]
> 
> I always thought the cursor approach you've discussed before was 
> interesting, but I never played around with it much myself.
> 
> It looks to me like your cursor implementation operates similar to 
> Optional types (as in the optional package). Does that make sense?

I haven't looked at it in depth, but the concept is probably the same. A 
cursor necessarily points at an element, and contains a boolean to 
denote emptiness.

The idea was a compromise to try and get the dcollections concept into 
Phobos. Originally, dcollections used iterators (and was D1). Ranges 
were added for the D2 port. Andrei wouldn't let it be considered for 
phobos, so I came up with the idea of making the iterators safe (and it 
actually is a nice concept too) by making them tiny ranges, but 
retaining the utility of an iterator for referencing.

In the end, Andrei built his own thing anyway, but the red black tree in 
phobos came from dcollections.

-Steve


More information about the Digitalmars-d mailing list