aget
doesn’t work like that. If you pass it additional indices it assumes they’re for nested arrays lookup. Basically, it’s to get from 2d or nd arrays. Not to get multiple values out of a 1d array.
Also, even if it did work as you thought, it’s not different to copeOfRange, in that it would still just copy the elements over to a new data structure.
What @plexus is saying is more complicated. But basically, subvec only returns a view over the vector. Because of that, no new vector is created, primitive values are not copied, and nothing is looked up yet. So it’s O(1) and takes O(1) extra memory.
copyOfRange is O(n) and takes O(n) memory.
To do what @plexus suggests over arrays, you would need to create a new ADT, which would just wrap a pointer to the array and keep track of start and end.
Since arrays are not interfaces in Java, you can’t create an ADT that can pass for an array. But you could implement some other collection interface, where under the hood it just delegates to your existing array.
The risk of doing that with arrays, is that unlike persistent vectors, they’re not immutable. So someone modifying the array elsewhere could change the elements of your subarray view without you knowing. That’s the advantage and reason why I’d suggest copyOfRange for arrays.
That said, I think Java actually has such a thing. It’s called Spliterator. It is used by Java Streams (the sequences of Java).
By using the steam API, you could get back such a view as a stream. But Clojure doesn’t support inerop with Java streams (unless I’m wrong).
All in all, better not bother. Also, I would rethink why you have an array in the first place ideally, especially if you are concerned with the cost of copying.