About racket/class system, I still have some confusion. Can Racket’s handle multiple inheritance about fields?
For example: (define core-1-interface (interface () get-state))
(define core-1-mixin
(mixin () (core-1-interface)
(super-new)
(init-field state)
(define/public (get-state)
state)
))
(define core-2-interface (interface () get-state))
(define core-2-mixin
(mixin () (core-2-interface)
(super-new)
(init-field state)
(define/public (get-state)
state)
))
;; How to do name resolution for double-core?
(define double-core% (core-2-mixin
(core-1-mixin
object%)))
; Error:
; class*: superclass already contains method
; superclass: #<class:...lict/double-core.rkt:5:2>
; method name: get-state
In this example, both core-1
and core-2
have the field state
and the method get-state
, they are the same name. Can I define a class double-core
by reusing core-1
and core-2
?
Note that if get-state
are pure methods (or assume they share state), then we can abstract two traits to work around it. e.g. define core-1-trait
and core-2-trait
, and use trait-alias
and trait-sum
to flatten them. That means they will use the same (one) state
in some class eventually. But here, the state
in core-1
and state
in core-2
are two different states. How racket/class system handle this situation? Thanks.
@st8l3ss has joined the channel