From: Tim Bradshaw
Subject: Re: design question
Date: 
Message-ID: <ey3itk4ljab.fsf@cley.com>
* iscaris  wrote:
> Style A: Font Arial, Size 12
> Style B: Bold, inherits everythng else from Style A, resulting in Arial, 12,
> bold

> What's the best design for such a system where an object inherits not from
> another class, but from an _instance_ of a class?

This is what I use.  It's not necessarily the best solution or the
best implementation of that solution.

    (defclass defaulting-mixin ()
      ((defaulting-parent :initform nil
                          :initarg :defaulting-parent)))

    (defgeneric slot-value/defaulting (o slot-name))

    (defmethod slot-value/defaulting (o slot-name)
      (slot-value o slot-name))

    (defmethod slot-value/defaulting ((o defaulting-mixin) slot-name)
      (if (and (slot-exists-p o slot-name)
               (slot-boundp o slot-name))
          (slot-value o slot-name)
          ;; might not want to blunder on regardless here.
          (slot-value/defaulting (slot-value o 'defaulting-parent)
                                 slot-name)))

--tim

From: Vladimir V. Zolotych
Subject: Re: design question
Date: 
Message-ID: <3ADC07CC.D104C3B2@eurocom.od.ua>
Tim Bradshaw wrote:
> 
>     (defgeneric slot-value/defaulting (o slot-name))

What purpose this above serves for ? Would you mind say
few words about that ?

-- 
Vladimir Zolotych                         ······@eurocom.od.ua
From: Tim Bradshaw
Subject: Re: design question
Date: 
Message-ID: <nkj1yqriy2e.fsf@tfeb.org>
"Vladimir V. Zolotych" <······@eurocom.od.ua> writes:

> Tim Bradshaw wrote:
> > 
> >     (defgeneric slot-value/defaulting (o slot-name))
> 
> What purpose this above serves for ? Would you mind say
> few words about that ?

It doesn't really do anything in this case other than to serve as an
indication that I'm going to define some methods on this GF.  I tend
to use DEFGENERIC even when it's not needed because it gives some
central place to put documentation or commentary (in this case there's
neither, sorry!).

I actually improved this stuff somewhat last night, I'll post the
souped-up one tonight (UK time) when I have access to my home machines
again.  It makes SLOT-VALUE/DEFAULTING return a second value which is
the object where the slot was found which tells you if it was a
default or directly present in the original instance, and has some
macrology to define defaulting accessors.

--tim
From: Marco Antoniotti
Subject: Re: design question
Date: 
Message-ID: <y6c1yqrd3rr.fsf@octagon.mrl.nyu.edu>
Tim Bradshaw <···@tfeb.org> writes:

> "Vladimir V. Zolotych" <······@eurocom.od.ua> writes:
> 
> > Tim Bradshaw wrote:
> > > 
> > >     (defgeneric slot-value/defaulting (o slot-name))
> > 
> > What purpose this above serves for ? Would you mind say
> > few words about that ?
> 
> It doesn't really do anything in this case other than to serve as an
> indication that I'm going to define some methods on this GF.  I tend
> to use DEFGENERIC even when it's not needed because it gives some
> central place to put documentation or commentary (in this case there's
> neither, sorry!).

THere is another good use of DEFGENERIC.  Suppose you are writing a
large system and that you have a "protocol" that must be obeyed by
subclasses (some of which do depend on other parts of the system).
E.g.

File 1:

(defclass a-root () ())

(defgeneric f (a-root))
(defgeneric g (a-root))

File 2:

(defun foo (x)
  (f x))

File 3:

(defclass another-root () ())

File 4:

(defclass the-real-mccoy (a-root another-root) ())

(defmethod f ((x the-real-mccoy)) ...)


In this case you can make File 2 depend only on File 1.  'f' will be
recognized as a generic function and you will avoid warnings (or
errors) depending on your PCL implementation.
On top of that you do achieve modularization.

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group	tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA			http://bioinformatics.cat.nyu.edu
	       "Hello New York! We'll do what we can!"
			Bill Murray in `Ghostbusters'.