【发布时间】:2016-01-31 17:24:11
【问题描述】:
当我将数据传递到 clojure 中的两个哈希映射时,我不断得到空映射,我知道数据是通过函数发送的,因为我使用了显示正确数据的打印语句,就在我关联数据时到地图上它似乎没有做任何事情,让我留下{}
谁能看到我做错了什么??
(defn sort-string [y]
(apply str (sort y)))
(defn get-unique [y]
(let [x (sort-string (str/lower-case y))
hashmap1 (hash-map)
hashmap2 (hash-map)]
(if-not (contains? hashmap1 x)
(assoc hashmap1 x, y)
(assoc hashmap2 y, y))
(if-not (get hashmap1 x) y)
(dissoc hashmap2 (get hashmap1 x))))
(for [strings '("door" " rood" "pen" "open" "high" "low" "wall" "lawl" "#")]
(get-unique strings))
【问题讨论】:
-
你期望的输出是什么?
-
小问题:
(hash-map)是一种非常规的写法{},contains?check 永远不会返回 true,因为它正在检查的哈希映射 100% 保证为空案例。 -
根据您对my answer 的评论,您正在尝试将字谜组合在一起,使用
sort-string生成对所有字谜都相同的东西,仅此而已。 请将此纳入您的问题。