Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Call-an-object-method/TXR/call-an-object-method.txr
Normal file
21
Task/Call-an-object-method/TXR/call-an-object-method.txr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(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
|
||||
Loading…
Add table
Add a link
Reference in a new issue