如何从另一个元素引用clojure映射中的元素?
{:num (calculate-num-function)
:sometext "Hello"
:double-num (* 2 :num)} ;; Is something like this possible?
答案 0 :(得分:1)
(let [m {:num (calculate-num-function) :sometext "Hello"}
m2 (assoc m :double-num (* 2 (:num m)))}] ... )
这是一种方法。
另:
(let [num (calculate-num-function)
m {:num num :sometext "Hello" :double-num (* 2 num)}] ...)
否则,不,你不能做你想做的事,也不需要这样做。