Do infinite bidirectional ranges make any sense?

Philippe Sigaud philippe.sigaud at gmail.com
Sat Aug 11 23:51:17 PDT 2012


On Sun, Aug 12, 2012 at 6:11 AM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:


> Can anyone think of any situation where an infinite bidirectional range would
> make any sense at all?

I find infinite ranges useful mainly to represent mathematical objects.

I used them only twice:

* to represent integers: front/popFront produced the positive
integers, whereas back/popBack dealt with the negative ones. I don't
remember if the first back would also return '0' or not...
* more generally, I once used them to group two infinite computations
(two ranges) under one abstraction. Again, front/popFront would
produce computation #1, and back/popBack would produce computation #2.


(This is not equal to grouping two ranges in a tuple, because the
resulting tuple is not a range... I guess the correct abstraction
would be what I call a 'revolving' range, which holds n ranges (same
element type) and a 'current'/'active' range. front/popFront would act
on the active range. Another function would, 'nextRange' change the
active one to the next range in the list. The range list is, of
course, itself a range. It's a range of ranges, but which exposes the
current range elements and not the current range itself.)


Anyway, I admit the infinite bidir ranges examples are a bit
far-feched. But I was quite happy to be able to use std.algo's full
power on such a contraption.


More information about the Digitalmars-d mailing list