문제

if I have a 2d vector like this:

[[1 2] [3 4] [5 6]]

Is this the best way to access an element at a co-ordinate [0, 0]

(get (get v 0) 0)

Or is there a better way?

도움이 되었습니까?

해결책

Use get-in to access a nested structure:

(get-in v [0 0]) ; => 1

다른 팁

get-in works as advertised but it destructuring can work as well.

(def v [[1 2] [3 4] [5 6]])
(let [[[a b][c d][e f]] v]
    a)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top