transcendental-lisp/lisp/object/this.lisp

44 lines
831 B
Common Lisp
Raw Normal View History

2017-03-06 11:00:18 -05:00
(load "../lang/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 ()
2017-03-06 11:00:18 -05:00
(setf count (+ count 1)))
(:inc-3 ()
(funcall this :inc)
(funcall this :inc)
2017-03-06 11:00:18 -05:00
(funcall this :inc))
(:dec ()
2017-03-06 11:00:18 -05:00
(setf count (- count 1)))
(:dec-3 ()
(funcall this :dec)
(funcall this :dec)
2017-03-06 11:00:18 -05:00
(funcall this :dec))
(:get ()
2017-03-06 11:00:18 -05:00
count)
(:set (value)
2017-03-06 11:00:18 -05:00
(setf count value))
(t ()
2017-03-06 11:00:18 -05:00
(cons name count)))))))
(let ((instance (counter 0)))
2017-03-06 11:00:18 -05:00
(defun my-counter (&rest args) (apply instance args)))
(setf my-counter2 (counter 10000))