我试图通过散列图音译列表,如下所示:
(map {"a" 0 "b" 1 "c" 2} ["a","c","b","a"])
我想吐出来的东西:
[0,2,1,0]
我该怎么做?
更正:上述方法有效,但不是这样:
(map {"a" 0 "b" 1 "c" 2} (vec "acba"))
这里有什么不同?
答案 0 :(得分:4)
使用mapv
代替
user=> (map {"a" 0 "b" 1 "c" 2} ["a" "c" "b" "a"])
(0 2 1 0)
user=> (mapv {"a" 0 "b" 1 "c" 2} ["a" "c" "b" "a"])
[0 2 1 0]
此外:
user=> (map {"a" 0 "b" 1 "c" 2} (vec "acba"))
(nil nil nil nil)
user=> (vec "acba")
[\a \c \b \a]
user=> (= \a "a")
false
这有效(但是很环绕):
user=> (mapv {"a" 0 "b" 1 "c" 2} (map str (vec "acba")))
(0 2 1 0)