我想将值附加到Clojure原子中的列表:
(def thing (atom {:queue '()}))
Run Code Online (Sandbox Code Playgroud)
我知道当它不是原子时,我可以这样做:
(concat '(1 2) '(3))
Run Code Online (Sandbox Code Playgroud)
我怎样才能将其翻译成交换!命令?
注意:我问了一个涉及地图的类似问题:在Clojure原子中使用swap到MERGE(追加)嵌套地图?
user=> (def thing (atom {:queue '()}))
#'user/thing
user=> (swap! thing update-in [:queue] concat (list 1))
{:queue (1)}
user=> (swap! thing update-in [:queue] concat (list 2))
{:queue (1 2)}
user=> (swap! thing update-in [:queue] concat (list 3))
{:queue (1 2 3)}
Run Code Online (Sandbox Code Playgroud)