transcendental-lisp/lisp/this.lisp

58 lines
927 B
Common Lisp
Raw Normal View History

(load "dlambda.lisp")
(defun counter (initial-count)
(let ((count initial-count)
2017-03-03 15:06:49 -05:00
(name nil)
(this nil))
2017-03-03 15:06:49 -05:00
(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 ()
2017-03-03 15:06:49 -05:00
(cons name count)
)
)
)
)
)
)
(let ((instance (counter 0)))
(defun my-counter (&rest args) (apply instance args))
)
(setf my-counter2 (counter 10000))