Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Polymorphic-copy/TXR/polymorphic-copy.txr
Normal file
25
Task/Polymorphic-copy/TXR/polymorphic-copy.txr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(defstruct base ()
|
||||
(:method identify (self) (put-line "base")))
|
||||
|
||||
(defstruct derived (base)
|
||||
(:method identify (self) (put-line "derived")))
|
||||
|
||||
(defstruct poly ()
|
||||
obj
|
||||
|
||||
(:method deep-copy (self)
|
||||
(let ((c (copy self))) ;; make copy of s
|
||||
(upd c.obj copy) ;; copy self's obj
|
||||
c))) ;; return c
|
||||
|
||||
;; Test
|
||||
|
||||
(let* ((b (new base))
|
||||
(d (new derived))
|
||||
(p (new poly obj d)))
|
||||
b.(identify) ;; prints base
|
||||
d.(identify) ;; prints derived
|
||||
|
||||
(let ((c p.(deep-copy)))
|
||||
p.obj.(identify) ;; prints derived
|
||||
(prinl (eq p.obj c.obj)))) ;; prints nil: c.obj is not a ref to p.obj
|
||||
Loading…
Add table
Add a link
Reference in a new issue