From: Vladimir Zolotykh
Subject: class precedence list
Date: 
Message-ID: <3BDE75D2.87A7097D@eurocom.od.ua>
Consider the following pathological case:

(defclass mystream () ())
(defclass buffered-mystream (mystream) ())
(defclass disk-mystream (buffered-mystream) ())
(defclass char-mystream (mystream) ())
(defclass ascii-mystream (char-mystream) ())
(defclass ascii-disk-mystream
    (ascii-mystream buffered-mystream disk-mystream)
  ())

There is an error here. What time this error should be detected
by Lisp ? Should this happen when I try to define ascii-disk-mystream?
If not, please say when.

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua
From: Pierre R. Mai
Subject: Re: class precedence list
Date: 
Message-ID: <87ofmpqruv.fsf@orion.bln.pmsf.de>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> Consider the following pathological case:
> 
> (defclass mystream () ())
> (defclass buffered-mystream (mystream) ())
> (defclass disk-mystream (buffered-mystream) ())
> (defclass char-mystream (mystream) ())
> (defclass ascii-mystream (char-mystream) ())
> (defclass ascii-disk-mystream
>     (ascii-mystream buffered-mystream disk-mystream)
>   ())
> 
> There is an error here. What time this error should be detected
> by Lisp ? Should this happen when I try to define ascii-disk-mystream?

The conflict in the class precedence lists has to be detected at class
finalization time.  At the latest that will be the time you create
your first instance of the given class, but it can be much earlier,
e.g. if all other classes are already known, like in this case, then
it can happen as early as class definition time.

The error has to happen, because CL can't compute a CPL that matches
your specification:

By including buffered-mystream in-front of disk-mystream, you request
that buffered-mystream appears in-front of disk-mystream in the CPL,
yet the CPL of disk-mystream requires that buffered-mystream appears
after itself in every CPL in which it appears.  Hence the conflict.

If you write instead

(defclass ascii-disk-mystream  ; Shouldn't this be ascii-disk-buffered-stream?
    (ascii-mystream disk-mystream buffered-mystream)
  ())

then everything will work all-right.  Simple rule:  If you include
both classes and (one of) their super-classes in a CPL, then the
super-classes will have to appear after the classes themselves.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein