The other answers are probably all you need, but if you do 2D indexing a lot - maybe along with other transformations of two-dimensional number structures - you can look in core.matrix . Switching between different core.matrix implementations with different performance characteristics is usually a one-line change. One of the implementations consists of operations with Clojure vectors. Here's how you would do dual indexing in core.matrix:
user=> (use 'clojure.core.matrix) nil user=> (def m (matrix [[1 2 3][4 5 6]])) #'user/m user=> (mget m 1 1) 5
For this particular operation, core.matrix does not offer much benefit. If you want to iterate over a matrix to generate a new one, here is one way to do this:
user=> (emap inc m) [[2 3 4] [5 6 7]]
Of course, this is not very difficult to do with the basic functions of Clojure. Whether core.matrix is useful depends on what you want to do, obviously.
source share