我已阅读 Racket 指南 13.7.3 Parameterized Mixins
我使用参数化 Mixinsgood-eat-fish%
从fish%
(define fish-interface
(interface () eat get-size))
(define fish%
(class* object% (fish-interface)
(init size)
(super-new)
(define current-size size)
(define/public (get-size) current-size)
(define/public (eat other)
(set! current-size (+ current-size (send other get-size))))))
(define (good-eat-mixin member-name)
(define eat member-name)
(mixin () ()
(inherit eat)
(define/public (good-eat y)
(eat y) (eat y))))
(define good-eat-fish%
((good-eat-mixin (member-name-key eat)) fish%))
当我运行代码时,会引发以下错误:
"mixin: method was referenced in definition, but is not in any of the from-interfaces
method name: eat
from-interfaces:"
此错误消息是否表明没有eat
方法?
如果我将代码更改为
(define (good-eat-mixin member-name)
(define eat member-name)
(mixin (interface () eat) (interface () eat good-eat)
(inherit eat)
(define/public (good-eat y)
(eat y) (eat y))))
我收到此错误:
interface: bad syntax in: interface
不幸的是,我不知道为什么
interface () eat)
语法不好。