Welcome! Please see the About page for a little more info on how this works.

+4 votes
in Collections by

dtype-next, libpython-clj, and tech.ml.dataset all assign special meaning to ranges but they often have to deconstruct them to do so. For libpython, we create actual python ranges in some cases. For dtype-next and friends, a range with increment of 1 may indicate a sub-buffer operation as opposed to an indexed-buffer operation -- sub-buffer retains the ability for System/arraycopy and the like to work correctly and is thus a major optimization in some cases.

I would like to be able to get the start, step, and end (when it exists) from any object created via clojure.core/range. I can currently do this via reflection or via subtraction of the first and second members of the sequence generated via the range along with count but I think it may be a safe and reasonable change to be able to query this information directly.

Most of this could be achieved by simply making the members start, step, and end members of LongRange and Range public as they are already final.

As a separate discussion it may be worth considering having finite ranges work like persistent vectors. I don't want to confuse the above point with this one but it sometimes more efficient to index into ranges via nth or an IFn invoke pathway than it is to use Clojure's sequence abstraction. Finite ranges are logically to me more like persistent vectors in nature and potentially they could behave precisely like persistent vectors including w/r/t hashcode, deriving from java.util.RandomAccess, and having conj produce either a new range or a persistent vector depending on if the value fits properly in the sequence.

Please log in or register to answer this question.

...