58 lines
927 B
Common Lisp
58 lines
927 B
Common Lisp
(load "dlambda.lisp")
|
|
|
|
(defun counter (initial-count)
|
|
(let ((count initial-count)
|
|
(name nil)
|
|
(this nil))
|
|
|
|
(setf name "Counter")
|
|
|
|
(setf this
|
|
(eval
|
|
(dlambda
|
|
|
|
(:inc ()
|
|
(setf count (+ count 1))
|
|
)
|
|
|
|
(:inc-3 ()
|
|
(funcall this :inc)
|
|
(funcall this :inc)
|
|
(funcall this :inc)
|
|
)
|
|
|
|
(:dec ()
|
|
(setf count (- count 1))
|
|
)
|
|
|
|
(:dec-3 ()
|
|
(funcall this :dec)
|
|
(funcall this :dec)
|
|
(funcall this :dec)
|
|
)
|
|
|
|
(:get ()
|
|
count
|
|
)
|
|
|
|
(:set (value)
|
|
(setf count value)
|
|
)
|
|
|
|
(t ()
|
|
(cons name count)
|
|
)
|
|
|
|
)
|
|
)
|
|
)
|
|
|
|
)
|
|
)
|
|
|
|
(let ((instance (counter 0)))
|
|
(defun my-counter (&rest args) (apply instance args))
|
|
)
|
|
|
|
(setf my-counter2 (counter 10000))
|