C++ / Why Iterators Got It All Wrong

Robert M. Münch via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 4 08:54:43 PDT 2017


On 2017-09-03 12:46:05 +0000, Moritz Maxeiner said:

> I'll put in on my ever growing list of things to check out in depth, thanks :p

You're welcome. Don't wait to long ;-)

>> There is no difference between code & data in Rebol. And it has a very 
>> rich set of datatpye, IIRC about 35 native ones. And many of them are 
>> series, which can be operated in the same way.
> 
> Sounds like LISP :)

Yes, some ideas are the same. But the syntax is way more beautyful and useable.

> I agree, though I was talking about what the abstract data type of a 
> "series" is, i.e. what operations is exposes. From my observation:
> A D input range exposes via empty/front/popFront.
> A classic iterator exposes via begin/end.
> A Rebol series seems to be a safer form of iterator, as it doesn't 
> expose begin/end directly, but exposes restricted operations that are 
> defined as manipulating begin/end.

The series has elements and a "current pointer" which can be 
manipulated. Begin & end are just that, begin and end of the series. 
You don't manipulate them directly. Of couse you can change a series by 
adding/removing, cutting etc. which then changes begin/end accordingly.

>> a: [a b c d e f g]
== [a b c d e f g]
>> a/5
== e
>> skip a 5
== [f g]
>> a
== [a b c d e f g]
>> b: a/5
== e
>> type? b
== word!
>> type? a
== block!
>> b: skip a 5
== [f g]
>> type? b
== block!
>> index? b
== 6
>> head b
== [a b c d e f g]

You can even treat such a block as fixed-size record and operate on 
this. Very handy.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d mailing list