3

我想从下面返回的序列的每个元素创建一个向量,以(vector. 我知道(vector得到我想要的东西的方法是错误的。它只是一个占位符。

我正在努力解决如何从三个序列中取出第一个元素并得到 ["abc-de-fghi" smith barney] [def-hi-jklm" ox todd],然后是第二个元素,第三个,依此类推.

感谢您的帮助。

(defn test-key-exclusion
    "This function takes csv-data1 (the includees) and tests to see
     if each includee is in csv-data2 (the includeds). This function
     also gathers enough other data, so that excludees (those not found),
     can be identified."

    [csv-data1 pkey-idx1 csv-data2 pkey-idx2 lnam-idx fnam-idx]

    (let [full-row-ret (map #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1)
          filtered-row-ret (filter (complement nil?) full-row-ret)]
        filtered-row-ret
        (vector     (map #(nth %1 pkey-idx1 nil)  filtered-row-ret)
                    (map #(nth %1 lnam-idx nil)   filtered-row-ret)
                    (map #(nth %1 fnam-idx nil)   filtered-row-ret))))

编辑:解决方案

我结束了以下从多个序列的每个元素创建一个向量。

(defn test-key-exclusion
    "This function takes csv-data1 (the includees) and tests to see
     if each includee is in csv-data2 (the includeds). This function
     also gathers enough other data, so that excludees (those not found),
     can be identified."

    [csv-data1 pkey-idx1 csv-data2 pkey-idx2 lnam-idx fnam-idx]

    (map (fn [row]
            (vector (nth row pkey-idx1 nil)
                    (nth row lnam-idx nil)
                    (nth row fnam-idx nil)))

         (filter (complement nil?)
            (map #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1))))
4

1 回答 1

7

我认为你需要的只是map. 它可以采用多个集合:

user> (map vector [1 2 3] [:a :b :c] ["a" "b" "c"])
([1 :a "a"] [2 :b "b"] [3 :c "c"])
于 2012-05-09T20:41:53.420 回答