类 / 方法

; Clojure has no void methods: every function returns a value.
; The closest thing is a function called only for its effect on an atom

(def counter (atom 0))

(defn inc-by [value] (swap! counter + value) nil)
(defn inc-by-amount [value amount] (swap! counter + (* value amount)) nil)

(inc-by 1)
; counter is 1
(println @counter)

(inc-by-amount 2 5)
; counter is 11
(println @counter)