2017-03-01 16:45:48 -05:00
|
|
|
(load "dlambda.lisp")
|
|
|
|
|
|
|
|
(defun fruit-counter (initial-count)
|
|
|
|
|
|
|
|
(let ((apple-count initial-count)
|
|
|
|
(banana-count initial-count)
|
|
|
|
(coconut-count initial-count))
|
|
|
|
|
|
|
|
(eval
|
|
|
|
(dlambda
|
2017-03-02 10:29:59 -05:00
|
|
|
|
|
|
|
(:inc-apple ()
|
|
|
|
(setf apple-count (+ apple-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:dec-apple ()
|
|
|
|
(setf apple-count (- apple-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:get-apple ()
|
|
|
|
apple-count
|
|
|
|
)
|
|
|
|
|
|
|
|
(:set-apple (value)
|
|
|
|
(setf apple-count value)
|
|
|
|
)
|
|
|
|
|
|
|
|
(:inc-banana ()
|
|
|
|
(setf banana-count (+ banana-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:dec-banana ()
|
|
|
|
(setf banana-count (- banana-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:get-banana ()
|
|
|
|
banana-count
|
|
|
|
)
|
|
|
|
|
|
|
|
(:set-banana (value)
|
|
|
|
(setf banana-count value)
|
|
|
|
)
|
|
|
|
|
|
|
|
(:inc-coconut ()
|
|
|
|
(setf coconut-count (+ coconut-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:dec-coconut ()
|
|
|
|
(setf coconut-count (- coconut-count 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
(:get-coconut ()
|
|
|
|
coconut-count
|
|
|
|
)
|
|
|
|
|
|
|
|
(:set-coconut (value)
|
|
|
|
(setf coconut-count value)
|
|
|
|
)
|
|
|
|
|
2017-03-01 16:45:48 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
2017-03-02 10:29:59 -05:00
|
|
|
|
|
|
|
; Create an instance
|
|
|
|
;
|
|
|
|
; usage:
|
|
|
|
; ~ (my-counter :set-apple 23)
|
|
|
|
; 23
|
|
|
|
;
|
|
|
|
(let ((instance (fruit-counter 0)))
|
|
|
|
(defun my-counter (&rest args) (apply instance args))
|
|
|
|
)
|
|
|
|
|
|
|
|
; Another way
|
|
|
|
;
|
|
|
|
; usage:
|
|
|
|
; ~ (funcall my-counter2 :set-apple 23)
|
|
|
|
; 23
|
|
|
|
;
|
|
|
|
(setf my-counter2 (fruit-counter 10000))
|
|
|
|
|