It's not about long vs int types since integer number literals in Clojure are always longs. It's about the range of the value and the fact that it doesn't fit into Java's int
.
I don't know for certain but I can speculate that the limit is due to practicality.
Strings and arrays in Java have a size limit that fits into int
. Generic List
interface can also be index only with int
.
Same for indexed Clojure collections. And while e.g. Clojure's persistent vectors could in theory use longs as the base index type since they rely on arrays of size 32, it wouldn't be very practical as even a plain array with Integer/MAX_VALUE
of 8-byte values will take 17 GB of RAM, and persistent vectors are not plain arrays.
As for anything lazy or without random access - using nth
with a high index there would be a very time-consuming anti-pattern. That's not to say that it's never needed, but someone needing it is a strong sign that a wrong data structure has been chosen for the problem at hand.