RFC on range design for D2

Bill Baxter wbaxter at gmail.com
Mon Sep 8 22:03:19 PDT 2008


On Tue, Sep 9, 2008 at 12:57 PM, Manfred_Nowak <svv1999 at hotmail.com> wrote:
> Andrei Alexandrescu wrote:
>
>> maybe "nextTo" or something could be more suggestive.
>
> r.tillBeg(s), r.tillEnd(s),
> r.fromBeg(s), r.fromEnd(s) ?

Another idea might be go back to Intro to Algebra with the "FOIL"
method for first,inner,outer,last.

Really you're trying to form the different elements of the cartesian
product of (rb,re) and (sb,se), so the "FOIL method" (a mnemonic for
multiplying binomials) tells you the resulting monomials are:

First:  (rb, sb)
Outer: (rb, se)
Inner: (re, sb)
Last: (re, se)

So you could have functions like:

fromFirsts(r,s)    aka  leftDiff(r,s)
fromLasts(s,r)    aka  rightDiff(r,s)  --- note the order reversal!
fromInner(r,s)     -- nonsense for ranges but would be "end of r to
beginning of s"
fromOuter(r,s)    aka leftUnion(r,s) aka rightUnion(s,r)

To me I think this way of decomposing the names makes it easier to
visualize what the things are doing.  I get no picture whatsoever from
"pullNext" and I think it's going to be really hard for me to remember
exactly what that does.  And leftUnion is also tough because it's
actually not a union of the two ranges, it's more like a union
followed by intersection with complement.

Thinking in terms of which components you're plucking out to make your
new iterator makes it easy for me to visualize.  But maybe not
everyone had the FOIL method drilled into their heads so thoroughly at
a young age like me.

Anyway I think it does suggest that maybe left and right union can
just be a single union op that goes from beginning of first arg to end
of second.  Maybe something like "span" would be a better name then.
And the precondition is that either r contains s, or vice versa.

--bb


More information about the Digitalmars-d-announce mailing list