transcendental-lisp/lisp/object/this.lisp

43 lines
797 B
Common Lisp
Raw Normal View History

2017-03-06 11:00:18 -05:00
(load "../lang/dlambda.lisp")
(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
(eval
(dlambda
(:inc ()
2017-03-07 16:27:11 -05:00
(setq count (+ count 1)))
(:inc-3 ()
2017-03-07 16:27:11 -05:00
(call this :inc)
(call this :inc)
(call this :inc))
(:dec ()
2017-03-07 16:27:11 -05:00
(setq count (- count 1)))
(:dec-3 ()
2017-03-07 16:27:11 -05:00
(call this :dec)
(call this :dec)
(call this :dec))
(:get ()
2017-03-06 11:00:18 -05:00
count)
(:set (value)
2017-03-07 16:27:11 -05:00
(setq 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)))
2017-03-07 16:27:11 -05:00
(setq my-counter2 (counter 10000))