22 lines
587 B
Plaintext
22 lines
587 B
Plaintext
(defvarl thing-count 0)
|
|
|
|
(defstruct thing ()
|
|
(call-count 0)
|
|
|
|
(:init (me)
|
|
(inc thing-count))
|
|
(:function get-thing-count () thing-count)
|
|
(:method get-call-count (me) (inc me.call-count)))
|
|
|
|
(let ((t1 (new thing))
|
|
(t2 (new thing)))
|
|
(prinl t1.(get-call-count)) ;; prints 1
|
|
(prinl t1.(get-call-count)) ;; prints 2
|
|
(prinl t1.(get-call-count)) ;; prints 3
|
|
(prinl t2.(get-call-count)) ;; prints 1
|
|
(prinl t2.(get-call-count)) ;; prints 2
|
|
(prinl t2.(get-call-count)) ;; prints 3
|
|
|
|
(prinl [t1.get-thing-count]) ;; prints 2
|
|
(prinl [t2.get-thing-count])) ;; prints 2
|