2012-05-10 35 views
4

我的問題是如何讓我的Clojure的線程宏之一在我的具體情況下工作?謝謝。如何正確使用線程宏?

我收到此錯誤:

(IllegalArgumentException Don't know how to create ISeq from: 
bene_csv.core$test_key_exclusion$fn__346 clojure.lang.RT.seqFrom (RT.java:487) 

當我調用該函數:

bene-csv.core=> (test-key-exclusion bene-data 1 gic-data 0 2 3) 

鑑於這種代碼 - 不必穿線宏工作液被註釋掉 -

(defn ret-non-match-rows 
    "Expects a sequence of sequences, like what is returned from clojure-csv. 
    Returns nil if there's a match; else returns failing row." 

    [s-o-s cmp-col-idx inq-row-idx inq-row] 

    (let [inq-row inq-row] 
     (loop [[row & remain-seq] s-o-s pos 0] 
      (let [cmp-val (nth inq-row inq-row-idx nil)] 
      (cond 
       (not row) inq-row 
       (= cmp-val (nth row cmp-col-idx)) nil 
       :not-found (recur remain-seq (inc pos))))))) 

(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 #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1) 
     (filter (complement nil?)) 
     (map (fn [row] 
       (vector (nth row pkey-idx1 nil) 
         (nth row lnam-idx nil) 
         (nth row fnam-idx nil)))))) 
(comment 
    (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))) 

資料與以下內容類似:

[["" "SMITHFIELD" "HAM"]["1123456789" "LITTLE" "CHICKEN"] ...] 

回答

15

您正在使用"thread-first" macro,但您應該使用"thread-last" macro來代替。與符號->>綁定的「線程最後」宏與「線程優先」宏具有相同的功能,只是它將表單作爲最後一個參數而不是第一個參數插入。

所以您的代碼會是這個樣子:

(->> (map #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1) 
    (filter (complement nil?)) 
    (map (fn [row] 
     (vector (nth row pkey-idx1 nil) 
       (nth row lnam-idx nil) 
       (nth row fnam-idx nil)))))) 
相關問題