こんなコードがあるとして
(define-class <point> () ((x :init-keyword :x :init-value 0) (y :init-keyword :y :init-value 0))) (define-method point ((p <point>)) (values (~ p 'x)(~ p 'y))) (define-method set-point! ((p <point>)(x <integer>)(y <integer>)) (set! (~ p 'x) x) (set! (~ p 'y) y) (point p)) (define-class <foo-point> (<point>) ()) (define-class <bar-point> (<point>) ()) (define-class <position> () ((foo :init-keyword :foo :init-value (make <foo-point>)) (bar :init-keyword :bar :init-value (make <bar-point>))))
結果がこうなわけですよ。すげーハマった・・・。
(define pos (make <position>)) (set-point! (~ pos 'foo) 100 100) ;; 100 ;; 100 (point (~ pos 'foo)) ;; 100 ;; 100 (define pos2 (make <position>)) (point (~ pos2 'foo)) ;; 100 ;; 100
正解はこうみたいだ。
(define-class <position> () ((foo :init-keyword :foo :init-form (make <foo-point>)) (bar :init-keyword :bar :init-form (make <bar-point>))))
希望通りこうなる。
(define pos (make <position>)) (set-point! (~ pos 'foo) 100 100) ;; 100 ;; 100 (point (~ pos 'foo)) ;; 100 ;; 100 (define pos2 (make <position>)) (point (~ pos2 'foo)) ;; 0 ;; 0
0 件のコメント:
コメントを投稿