2017-03-06 11:00:18 -05:00
|
|
|
(load "../lang/dlambda.lisp")
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(defun counter (initial-count)
|
|
|
|
(let ((count initial-count)
|
2017-03-03 15:06:49 -05:00
|
|
|
(name nil)
|
2017-03-03 11:56:27 -05:00
|
|
|
(this nil))
|
|
|
|
|
2017-03-03 15:06:49 -05:00
|
|
|
(setf name "Counter")
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(setf this
|
|
|
|
(eval
|
|
|
|
(dlambda
|
|
|
|
|
|
|
|
(:inc ()
|
2017-03-06 11:00:18 -05:00
|
|
|
(setf count (+ count 1)))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(:inc-3 ()
|
|
|
|
(funcall this :inc)
|
|
|
|
(funcall this :inc)
|
2017-03-06 11:00:18 -05:00
|
|
|
(funcall this :inc))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(:dec ()
|
2017-03-06 11:00:18 -05:00
|
|
|
(setf count (- count 1)))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(:dec-3 ()
|
|
|
|
(funcall this :dec)
|
|
|
|
(funcall this :dec)
|
2017-03-06 11:00:18 -05:00
|
|
|
(funcall this :dec))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(:get ()
|
2017-03-06 11:00:18 -05:00
|
|
|
count)
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(:set (value)
|
2017-03-06 11:00:18 -05:00
|
|
|
(setf count value))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
|
|
|
(t ()
|
2017-03-06 11:00:18 -05:00
|
|
|
(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
|
|
|
|
|
|
|
(setf my-counter2 (counter 10000))
|