Interface Racket:接口的前向声明
如果我有两个并排定义的接口,我希望在合同中的另一个接口中有每个接口的引用,即:Interface Racket:接口的前向声明,interface,scheme,racket,Interface,Scheme,Racket,如果我有两个并排定义的接口,我希望在合同中的另一个接口中有每个接口的引用,即: (define context-interface<%> (interface () [entity-list (->m (listof (is-a?/c entity-interface<%>)))] ) ) (define entity-interface<%> (interface () [on-add (->m (is-a?
(define context-interface<%>
(interface ()
[entity-list (->m (listof (is-a?/c entity-interface<%>)))]
)
)
(define entity-interface<%>
(interface ()
[on-add (->m (is-a?/c context-interface<%>) void?)]
)
(定义上下文接口
(接口()
[实体列表(->m(列表(is-a?/c实体接口)))]
)
)
(定义实体接口)
(接口()
[添加时(->m(是-a?/c上下文接口)无效?]
)
<>我应该怎样避免代码<定义之前不能引用一个标识符< /代码>错误?我没有发现任何像C++中的正向声明那样的意思,在我的前一个问题中,我知道有可能用<代码>懒惰的要求<代码>来解决问题,但是如果我想把两个定义都保存在S中,那该怎么办呢?ame源文件?您可以通过在协定的某个部分周围添加来修复递归协定中的这种“值未初始化”错误,以延迟该部分的评估,直到需要时为止。在这种情况下,您可以添加大约(is-a?/c实体接口)
(定义上下文接口
(接口()
[实体列表(->m(列表(递归契约(is-a?/c实体接口)))]
))
(定义实体接口)
(接口()
[添加时(->m(是-a?/c上下文接口)无效?]
))
请注意,它可以是
(is-a?/c实体接口)
,因为这是一个合约值,但它不能仅仅是实体接口
,因为这是一个racket/class接口值,而不是合约。此文档可能对您有很大帮助!我看到它可能是(递归合约(->m(listof(is-a?/c trait interface))
,但目前我不知道它是否会对性能等方面产生任何影响。这不是某种对递归契约的滥用吗(据我所知)为定义递归而创建?不,这不是滥用递归契约
。递归契约
增加了额外的惰性,因此性能影响可能类似于惰性承诺或流,但我不确定
(define context-interface<%>
(interface ()
[entity-list (->m (listof (recursive-contract (is-a?/c entity-interface<%>))))]
))
(define entity-interface<%>
(interface ()
[on-add (->m (is-a?/c context-interface<%>) void?)]
))