我正在尝试通过哈希图音译列表,如下所示:
(map {"a" 0 "b" 1 "c" 2} ["a","c","b","a"])
我想吐出:
[0,2,1,0]
我该怎么做呢?
更正:上述方法有效,但这不是:
(map {"a" 0 "b" 1 "c" 2} (vec "acba"))
这里有什么不同?
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)