transcendental-lisp/lisp/object/this.lisp

39 lines
714 B
Common Lisp
Raw Normal View History

(defun counter (initial-count)
2017-03-07 16:27:11 -05:00
(let ((this) (name)
(count initial-count))
2017-03-07 16:27:11 -05:00
(setq name "Counter")
2017-03-07 16:27:11 -05:00
(setq this
(dlambda
(:inc ()
(setq count (+ count 1)))
(:inc-3 ()
(call this :inc)
(call this :inc)
(call this :inc))
(:dec ()
(setq count (- count 1)))
(:dec-3 ()
(call this :dec)
(call this :dec)
(call this :dec))
(:get ()
count)
(:set (value)
(setq count value))
(t ()
(cons name count))))))
(let ((instance (counter 0)))
2017-03-06 11:00:18 -05:00
(defun my-counter (&rest args) (apply instance args)))
2017-03-07 16:27:11 -05:00
(setq my-counter2 (counter 10000))