From: Marco Antoniotti
Subject: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <K7Slb.60$KR3.16056@typhoon.nyu.edu>
Hi

I want to build something that does the following.

(defclass container ()
    ((s :accessor s :initarg 42)))

(defclass contained ()
    ((container :accessor part-of :initarg :part-of)
     (s :accessor s)))

(defvar *c* (make-instance 'container))

(defvar *i* (make-instance 'contained :part-of *c*))

(s *i*) ==> 42


My question is what would be the best way to build this without 
resorting to :metaclass (which is not portable)

I thought of defining a macro that does something like

(declare-part-of-inheritance contained s)

which expanded in an appropriate :before method on S, but I am not so 
satisfied.

I need some brainstorming about this.  I just cannot make up my mind.

Cheers
--
Marco

From: Marco Antoniotti
Subject: Re: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <S8Slb.61$KR3.16056@typhoon.nyu.edu>
Marco Antoniotti wrote:

> Hi
> 
> I want to build something that does the following.
> 
> (defclass container ()
>    ((s :accessor s :initarg 42)))
                      ^^^^^^^^

Should be :initform

Cheers
--
Marco
From: Frank A. Adrian
Subject: Re: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <_CYlb.57$o92.62722@news.uswest.net>
Marco Antoniotti wrote:

> Hi
> 
> I want to build something that does the following.
> 
> (defclass container ()
>     ((s :accessor s :initarg 42)))
> 
> (defclass contained ()
>     ((container :accessor part-of :initarg :part-of)
>      (s :accessor s)))
> 
> (defvar *c* (make-instance 'container))
> 
> (defvar *i* (make-instance 'contained :part-of *c*))
> 
> (s *i*) ==> 42
> 
> 
> My question is what would be the best way to build this without
> resorting to :metaclass (which is not portable)
> 
> I thought of defining a macro that does something like
> 
> (declare-part-of-inheritance contained s)
> 
> which expanded in an appropriate :before method on S, but I am not so
> satisfied.

Can the instance be contained in more than one container?  Is the nesting
going to be more than one deep?  Will you need to reflect internal method
calls in the delegate back down to the delegating instance (to solve the
"confused self" problem in delegation)?  Can plain functions be involved,
or will you need method support, as well?

My feeling is that you'd be able to hack a simplistic solution easily
enough.  The real question is how far you need to push this functionality. 
Simple and specific uses will only need a macros and simple functions.  If
you plan a general system based around this type of delegation, or have to
deal with method combos, there's not any really good way without using the
MOP, and as long as you're going there, you might as well define a proper
delegative dispatch system with multiple parents and method combination,
ala Self.  Of course, the idea of delegation for method lookup doesn't suit
itself as well for a system with multimethods (as opposed to the sanctioned
object method dispatch of most OO languages), although for varible lookup
it can still apply well, as long as the multiple inheritance issues are
looked after properly.

faa
From: Jeff Greif
Subject: Re: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <i2%lb.5308$mZ5.27718@attbi_s54>
One possibility is to consider having an object (or struct or pair)
represent the (part-of part container) relationship, which would allow a
part to be shared by multiple containers and various other "advanced"
features.  There could be a collections of all the part-of-relationship
objects allowing indexing by either part or container.

You'd then just say (make-part-of (make-instance 'part) (make-instance
'container)).

Jeff

"Frank A. Adrian" <·······@ancar.org> wrote in message
·······················@news.uswest.net...
> Marco Antoniotti wrote:
>
> > Hi
> >
> > I want to build something that does the following.
> >
> > (defclass container ()
> >     ((s :accessor s :initarg 42)))
> >
> > (defclass contained ()
> >     ((container :accessor part-of :initarg :part-of)
> >      (s :accessor s)))
> >
> > (defvar *c* (make-instance 'container))
> >
> > (defvar *i* (make-instance 'contained :part-of *c*))
> >
> > (s *i*) ==> 42
> Can the instance be contained in more than one container?  Is the nesting
> going to be more than one deep?  Will you need to reflect internal method
> calls in the delegate back down to the delegating instance (to solve the
> "confused self" problem in delegation)?  Can plain functions be involved,
> or will you need method support, as well?
>
From: Kenny Tilton
Subject: Re: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <oCSlb.29168$pT1.21142@twister.nyc.rr.com>
Marco Antoniotti wrote:
> Hi
> 
> I want to build something that does the following.
> 
> (defclass container ()
>    ((s :accessor s :initarg 42)))
> 
> (defclass contained ()
>    ((container :accessor part-of :initarg :part-of)
>     (s :accessor s)))
> 
> (defvar *c* (make-instance 'container))
> 
> (defvar *i* (make-instance 'contained :part-of *c*))
> 
> (s *i*) ==> 42
> 
> 
> My question is what would be the best way to build this without 
> resorting to :metaclass (which is not portable)
> 
> I thought of defining a macro that does something like
> 
> (declare-part-of-inheritance contained s)
> 
> which expanded in an appropriate :before method on S, but I am not so 
> satisfied.

I did something very much like declare-part-of-inheritance. But I am 
pretty sure it produced something like:

(defmethod s :around (self)
    (or (call-next-method)
        (when (container self)
            (s (container self)))))

You mention a before method so I gather you plan to shift the value into 
the contained instance so it is just there on subsequent calls. What if 
it changes in the container during their lifetime?

You can also:

(defmethod s (self) (declare (ignore self)))

and then the contained does not even need to have the slot. In which 
case, the semantics of (setf s) gets interesting.

Me, I use Cells, I never code SETF. :)


kenny


-- 
http://tilton-technology.com
What?! You are a newbie and you haven't answered my:
  http://alu.cliki.net/The%20Road%20to%20Lisp%20Survey
From: james anderson
Subject: Re: Best way to implement a PART-OF relationship on top of CLOS
Date: 
Message-ID: <3F97F908.B3911598@setf.de>
Marco Antoniotti wrote:
> 
> Hi
> 
> I want to build something that does the following.
> 
> (defclass container ()
>     ((s :accessor s :init[form] 42)))
> 
> (defclass contained ()
>     ((container :accessor part-of :initarg :part-of)
>      (s :accessor s)))
> 
> (defvar *c* (make-instance 'container))
> 
> (defvar *i* (make-instance 'contained :part-of *c*))
> 
> (s *i*) ==> 42
> 
> My question is what would be the best way to build this without
> resorting to :metaclass (which is not portable)
> 
> I thought of defining a macro that does something like
> 
> (declare-part-of-inheritance contained s)

reads like you want to do delegation. depends on where you want to stick the scalpel.

the compiler - with a macro for a caching delegation function. propably needs
to know the slot which will hold the reference

the function - either a general method, or a specific function class with a
method on no-applicable-method, which examines the instance and generates an accessor

the effective method - a method combination which does something similar.

the metaclass - ? not portable for slot access inflection, but can contribute
to one of the above in a portable

? do you really need to cache it?

...