我想在闭包中使用散列映射,因为我有一个for循环,将已排序的字符串和未排序的字符串传递给我的函数,我想要做的是两个if哈希地图上发言Clojure散列映射查询键和值
1 if语句是
if hash-map doesnt contain string "x"
put x in a new hash-set
第二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”之类的语句包含“put”等等,我该怎么办?
如果您将我的答案纳入问题中,那么我的答案不再有任何意义。我可能会最终删除它。我很确定这不是应该如此工作的方式。 –
你应该接受我的答案,然后撰写另一个新的问题。你也可以阅读'assoc'和'dissoc'。还有'conj'。然后集合和地图之间的区别。很可能你应该在你的问题中使用一套。 –