this repo has no description
1(def counter-prototype
2 @{:add (fn [self amount] (+= (self :_count) amount))
3 :increment (fn [self] (:add self 1))
4 :count (fn [self] (self :_count))})
5
6(defn new-counter []
7 (table/setproto @{:_count 0} counter-prototype))
8
9(def counter (new-counter))
10
11(print (:count counter))
12(:increment counter)
13(print (:count counter))
14(:add counter 3)
15(print (:count counter))
16
17(def Counter
18 (let [proto @{:add (fn [self amount] (+= (self :_count) amount))
19 :increment (fn [self] (:add self 1))
20 :count (fn [self] (self :_count))}]
21 (fn [] (table/setproto @{:_count 0} proto))))
22
23(def counter (Counter))
24(print (:count counter))
25(:increment counter)
26(print (:count counter))
27(:add counter 3)
28(print (:count counter))
29