[plt-scheme] Re: Multiple inheritance problem with mixins

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Feb 2 23:26:02 EST 2005

This problem in mixins does exist in general (see the LockedMagicDoor
example in http://www.ccs.neu.edu/scheme/pubs/tr97-293.pdf) but I think
you've simplified the example so much as to remove the real motivation?

In any case, I think that the proper fix for your first post's code is
to just not call the mixin from inside the definition of another mixin.
Instead just mix shared-mixin in once, at the end.

Like this:

(require (lib "macro.ss" "framework"))

(define shared<%>
  (interface ()
    get-expansion
    set-expansion))

(define shared-mixin
  (mixin () (shared<%>)
    (super-new)
    (define/public (set-expansion x) (void))
    (define/public (get-expansion) (void))))

(define tab-completion
  (mixin (shared<%>) ()
    (class %
      (super-new)
      (inherit set-expansion get-expansion))))

(define online-error-reporting
  (mixin (shared<%>) ()
    (super-new)
    (inherit set-expansion get-expansion)))

(define the-class% 
  (online-error-reporting 
   (tab-completion 
    (shared-mixin 
     object%))))

Robby

At Thu, 3 Feb 2005 12:55:14 +0900, Daniel Pinto de Mello e Silva wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Nevermind :)
> 
> (define sm<%>
>    (interface () get-expansion set-expansion))
> 
> (define (shared-mixin %)
>   (if (implementation? % sm<%>)
>       %
>      (class %
>         (super-new)
>         (define/public (set-expansion x) (void))
>         (define/public (get-expansion) (void)))))
> 
> 
> Daniel
> 
> 
> On Thu, 3 Feb 2005 12:44:21 +0900, Daniel Pinto de Mello e Silva
> <daniel.silva at gmail.com> wrote:
> > Hi,
> > I have some shared functionality between two mixins that shouldn't
> > know about each other.  I wanted to implement the shared functionality
> > as another mixin, but I get an error:
> > class*: superclass already contains method: m for class: stdin::57
> > 
> > Is there a good way to abstract out shared functionality from two
> > mixins?  This is the distilled example:
> > 
> > (require (lib "class.ss"))
> > 
> > (define (shared-mixin %)
> >   (class %
> >      (super-new)
> >      (define/public (set-expansion x) (void))
> >      (define/public (get-expansion) (void))))
> > 
> > (define (tab-completion %)
> >   (class (shared-mixin %)
> >      (super-new)
> >      (inherit set-expansion get-expansion)))
> > 
> > (define (online-error-reporting %)
> >   (class (shared-mixin %)
> >      (super-new)
> >      (inherit set-expansion get-expansion)))
> > 
> > (define the-class% (online-error-reporting (tab-completion object%)))
> > 
> > 
> > Daniel
> >



Posted on the users mailing list.