Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在 Scheme 中克隆一个对象,比如
(define o1 (new cl% [a 1] [b 2]))
接着
(define o2 o1)
当我使用设置!在 o1 上,它与 o1 一起改变了 o2。但我想要具有相同属性的独立克隆。我应该怎么办?
写一个复制方法。然后:
(define o2 (copy-cl%-thingy o1))
像这样:
(define (new aval bval) `(cl% [a ,aval] [b ,bval])) (define cl%-aval caddr) (define cl%-bval cadddr) (define (copy-cl%-thingy o) (new (cl%-aval o) (cl%-bval o)))