我的问题是如何捕获发生匹配的向量行的索引?在下面的代码中,我做错了什么?
我有一个向量的向量
(def v1 [[44 2 3 4 5][1 6 7 5 10][11 12 13 14 15]])
列索引和比较值
(def cmp-val1 11)
(def col-idx 0)
我想返回比较返回 true 的行索引。在 col-idx = 0 和 cmp-val1 = 11 的情况下,我应该看到 (first row-num) 返回 2,它返回 1。
(defn ret-match-row
"Return the index of the row, in which the cmp-val is found.
It is okay to increment 0."
[in-seq cmp-val col-idx]
(let [rn 0]
(let [row-num
(for [seq-row in-seq
:let [local-row-num (inc rn)]
:when (= cmp-val (nth seq-row col-idx nil))]
local-row-num)]
(first row-num))))
来自 lein repl:
bene-csv.core=> (ret-match-row v1 cmp-val1 col-idx)
1