racket-collections
racket-collections copied to clipboard
Range does not return a known finite sequence
At the moment, Racket's in-range
is simply re-provided as range
. As this doesn't encode known finiteness, it results in unexpected behavior when used with other APIs:
(empty? (range 0)) ;=> #t
(empty? (take 5 (range 0))) ;=> #f
(length (take 5 (range 3))) ;=> 5
This happens because take
and drop
return bounded sequences without forcing the input sequence if it isn't known-finite?
. For range
, this means that it returns a bounded sequence of length 5 (in the above example) even though the input is actually known finite and of length 3.
Suggested fix: Wrap in-range
with a sequence that implements gen:countable
and always returns true for known-finite?
.