2013-02-23 73 views
1
(defn GetValuesFromWhereCommand 
    "return a list of values from Where command" 
    [Query tableName] 
    (let [values (re-seq #"[0-9a-zA-Z_=<>]+" ((re-find #"WHERE(.*)" Query) 1)) 
     bitwise (re-find #"AND|OR" Query) 
     tempList (ref #{}) 
     ] 
    ; first loop will look for the operators = < > 
    (doseq [item values] 
    (let [result (case (re-find #"[=><]" item) 
     "=" (GetRowsfromCondition tableName item =) 
     "<" (GetRowsfromCondition tableName item <) 
     ">" (GetRowsfromCondition tableName item >) 
     nil (println "nothing") 
    )] 
    (when (not= nil result) (dosync (alter tempList conj result))) 
    tempList) 
    ) 
    (println tempList) 
    tempList)  ; get the Where from Update ',' 
) 

這裏是我的輸出。Clojure和/或集合

#<[email protected]: #{#<[email protected]: #{0}> #<[email protected]: #{0 1}>}> 

我想提出實施和操作,將返回#{0}
和或將返回#{0 1}。


我的問題是如何訪問我創建的列表。出於某種原因,我無法使用union/intersection。

回答

3

你應該DEREF所有內部設置和應用聯盟新的一組 它看起來應該財產以後這樣的:

(let [newList (ref #{})] (doseq [item @your_ref_to_set_of_refs] (dosync (alter newList conj @item))) (apply union @newList))