2012-05-10 3 views
4

제 질문은 어떻게하면 Clojure의 스레딩 매크로 중 하나를 얻을 수 있습니까? 고맙습니다. 매크로를 스레딩없이 솔루션을 작업 주석 - -어떻게 스레딩 매크로를 올바르게 사용합니까?

(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))) 
이 코드를 감안할 때

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

:이 함수를 호출 할 때

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

:

이 오류를 얻고있다

데이터는 다음과 유사합니다.

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

답변

15

"thread-first" macro을 사용하고 있지만 대신 "thread-last" macro을 사용해야합니다. ->> 기호에 바인딩 된 "thread-last"매크로는 양식을 첫 번째 인수 대신 마지막 인수로 삽입하는 것을 제외하고는 "스레드 우선"매크로와 동일한 기능을 수행합니다.

그래서 코드를 다음과 같이 보일 것입니다 :

(->> (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)))))) 
관련 문제