我尝试在闭包中使用hash-map,因为我有一个for循环,它将一个排序的字符串和一个未排序的字符串传递给我的函数,我想做的是在hash-map上使用两个if语句
第1条if语句为
if hash-map doesnt contain string "x"
put x in a new hash-set第2条if语句为
if hash-map key "x" value is not equal to "y"
remove "x" from hash-set这是我到目前为止所拥有的
(defn transform3 [y]
(let [x (sort-string (str/lower-case y))
my-hash-map (hash-map)
hashmap2 (hash-map)]
(if-not (contains? my-hash-map x)
(my-hash-map x, y)
(hashmap2 y))
(if-not (get hash-map x) y)
(dissoc hashmap2 x)
;;remove from hash-set to do...
))如果语句允许我使用"get“、"contains”、"put“等语句,我会怎么做?
发布于 2016-01-31 23:14:35
hash-map是一个函数。当您调用它(使用括号)时,它会返回一个实际的散列映射。我已经修改了您的代码,以克服那个特定的错误消息。
(defn add-to-map [y]
(let [x (sort-string (str/lower-case y))
my-hash-map (hash-map)]
(if-not (contains? my-hash-map x)
(hash-map x, y)
(hash-set y))
(if-not (get hash-map x) y)
;;remove from hash-set to do...
))https://stackoverflow.com/questions/35115224
复制相似问题