44 lines
831 B
Common Lisp
44 lines
831 B
Common Lisp
(load "../lang/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))
|