我在理解这些函数如何更新底层ref,atom等时遇到问题.
文档说:(应用f current-of-identity args)
(def one (atom 0))
(swap! one inc) ;; => 1
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何"扩展"到申请表格.没有提到申请表中究竟是什么'args'.它是一系列参数还是这些独立的值?
是"扩大"到:
(apply inc 0) ; obviously this wouldnt work, so that leaves only one possibility
(apply inc 0 '())
(swap! one + 1 2 3) ;; #=> 7
Run Code Online (Sandbox Code Playgroud)
是吗:
(apply + 1 1 2 3 '()) ;or
(apply + 1 [1 2 3])
(def two (atom []))
(swap! two conj 10 20) ;; #=> [10 20]
Run Code Online (Sandbox Code Playgroud)
是吗:
(apply conj [] [10 20]) ;or
(apply conj …Run Code Online (Sandbox Code Playgroud) clojure ×1