Range proposal

Bill Baxter wbaxter at gmail.com
Tue Sep 9 20:42:25 PDT 2008


The current range proposal may be putting too much emphasis on the
range being a contiguous linear entity.  As something which represents
a begin and and end and *everything in between*.  That is only true in
certain special cases.  Even with linked lists, you don't really have
that.  You just have two pointers that could be pointing to anywhere
in memory.  The range doesn't really represent everything in between
those pointers.  Other examples that contradict thinking of a range as
simply "here to there and everything in between" are infinite
generators, or random iterators (like the HMM example).

It may lead to a cleaner nomenclature if we acknowledge this fact, and
think of a range more as an iterator plus a sentinel, rather than
trying to emphasize the symmetry between the beginning and end items
that really only exists for special cases.

In this terminology the "left" thing points at the "value" and the
"right" thing is the "end".

Here's one way that could pan out:

** Basics
r.atEnd() -- instead of r.isEmpty()

** Input range/ Forward range
e = r.value      -- instead of r.left
r.next             -- still ok
r.moveTo(s)       -- instead of rightUnion
r.moveToEndOf(s)     -- instead of rightDiff

** Bidirectional range
r.last            -- instead of r.right
r.pop            -- ok as-is
r.moveEndToEndOf(s)             -- instead of leftUnion
   --> or just s.moveTo(r)
r.moveEndTo(s)                   -- instead of leftDiff

** Random access
ok as-is


So re-iterating, the basic idea is to think of a range as an iterator
with a current value, that happens to have an extra thing hanging
around, it's "end", a sentinel that marks a stopping condition.

Thoughts?
--bb



More information about the Digitalmars-d mailing list