2017-03-03 11:56:27 -05:00
|
|
|
(defun counter (initial-count)
|
2017-03-07 16:27:11 -05:00
|
|
|
(let ((this) (name)
|
|
|
|
(count initial-count))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-07 16:27:11 -05:00
|
|
|
(setq name "Counter")
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-07 16:27:11 -05:00
|
|
|
(setq this
|
2017-03-10 15:08:42 -05:00
|
|
|
(dlambda
|
|
|
|
(:inc ()
|
|
|
|
(setq count (+ count 1)))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:inc-3 ()
|
|
|
|
(call this :inc)
|
|
|
|
(call this :inc)
|
|
|
|
(call this :inc))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:dec ()
|
|
|
|
(setq count (- count 1)))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:dec-3 ()
|
|
|
|
(call this :dec)
|
|
|
|
(call this :dec)
|
|
|
|
(call this :dec))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:get ()
|
|
|
|
count)
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(:set (value)
|
|
|
|
(setq count value))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-10 15:08:42 -05:00
|
|
|
(t ()
|
|
|
|
(cons name count))))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
(let ((instance (counter 0)))
|
2017-03-06 11:00:18 -05:00
|
|
|
(defun my-counter (&rest args) (apply instance args)))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-07 16:27:11 -05:00
|
|
|
(setq my-counter2 (counter 10000))
|