[plt-scheme] Re: overriding fields

From: Corey Sweeney (corey.sweeney at gmail.com)
Date: Mon Apr 11 17:32:54 EDT 2005

i got a solid example of this of reasonable length:

  (define thing<%>
    (interface () the-call))

(define a-mixin
  (mixin () (thing<%>)
    ;; stubs
    (init stuff)
    (define thing stuff)
    (define/public (the-call) (display thing))

(define b-mixin
  (mixin (thing<%>) (thing<%>)
;override and call self for no reason
;    (define/override (the-call) (lambda () (super the-call)))   ;uncomment
;    (define/public (call-this) (lambda () (super the-call)))       ;uncomment
    (inherit the-call)                                                
    (define/public (call-this) (lambda () (the-call)))                  ;comment
    (super-new (stuff "inside"))))

(define c-mixin
  (mixin (thing<%>) (thing<%>)
    (init stuff)
    (define thing stuff)
    (define/override (the-call) 
      (display thing))
(define newobj
  (new (c-mixin (b-mixin (a-mixin object%)))
       (stuff "outside")))
((send newobj call-this))

;;wanted "inside" but we get "outside",  we can get inside by changing
the commened lines in b-mixin

i just found this is the manual:
* overriding: Some methods declared in a superclass can be replaced in
the derived class. References to the overridden method in the
superclass use the implementation in the derived class.

is this example what the manual is refering to?


On 4/11/05, Corey Sweeney <corey.sweeney at gmail.com> wrote:
> i'm having some trouble trying to override fields.  i tried thowing
> the field as a closure in a let, and then just provide accessors, but
> it's still not working. the problem is:
> a% -> (define/public (get-thing))
> b% (inherits from a%) -> (define/public (somefunction) ...(get-thing)...)
> c% (inherits from b%) -> (override* (define-public (get-thing)))
> my problem is that when i call (send b somefunction), (get-thing)
> references the data in it's subclass c%, not it's superclass a%.  is
> there a special mechanism that i have to use for overriding fields?
> Corey

Posted on the users mailing list.