digitalmars.D - Do infinite bidirectional ranges make any sense?
Jonathan M Davis <jmdavisProg gmx.com> writes:
As far as I can tell, there's nothing technically stopping an infinite range from being bidirectional, but I can't think of any case where such a range makes any sense at all. isRandomAccessRange is written specifically to allow infinite forward ranges be random access without being bidirectional (unlike non-infinite random-access ranges which must be bidirectional). But I don't see anything else which either supports or stops infinite ranges from being bidirectional. I'm working on creating a small testing framework for ranges so that it's easy to generate the exact range type that you want (with regards to both the type of range - forward, random-access etc. - as well as other attributes of the range such as hasLength and hasSlicing), and I can't decide whether I should make it possible for it to generate infinite bidirectional ranges or not. If there are truly zero use cases where they make any sense, then I see no point in coding for them, but if they _are_ possible and reasonable, then I need to take them into account. Can anyone think of any situation where an infinite bidirectional range would make any sense at all? - Jonathan M Davis
Aug 11 2012
"bearophile" <bearophileHUGS lycos.com> writes:
Jonathan M Davis:Can anyone think of any situation where an infinite bidirectional range would make any sense at all?
I have implemented a simple Turing machine (to test a busy beaver) in D where the tape is finite in both directions, but when the machine tries to write past one of the ends of the tape, it grows longer as needed. I have not used ranges to implement this, but maybe they are usable for this. Bye, bearophile
Aug 12 2012