在Racket中,这会给我一个错误:
为了让它工作,我需要将最后两行替换为:
(struct point-in-plane (pos_x pos_y))
(struct pixel point-in-plane (color))
(define a-pixel (pixel 1 2 "blue"))
(pixel-color a-pixel)
(pixel-pos_x a-pixel)
(pixel-pos_y a-pixel)
为了让它工作,我需要将最后两行替换为:
(point-in-plane-pos_x a-pixel)
(point-in-plane-pos_y a-pixel)
同样的,在R6RS中
#!r6rs
(import (rnrs))
(define-record-type point (fields x y))
(define-record-type cpoint (parent point) (fields color))
(define blue-point (make-cpoint 1 2 "blue"))
(write (cpoint-x blue-point))
出现了类似的错误。
Scheme(和Racket)为什么不允许您访问在父级中定义的子类型的字段,而不是通过parenttypeID-fieldID而是subtypeID-fieldID呢?
也就是说,在我的情况下,允许我使用pixel-pos_x和pixel-pos_y。