From: Andreas Thiele
Subject: (MOP) coding suggestion?
Date: 
Message-ID: <d939mq$5vr$01$1@news.t-online.com>
I need a function which returns a list of all derived subclasses for a given
class. It should contain the class itself. I wrote the following:

(defun class-and-subclasses (class)
  (let ((s (class-direct-subclasses class)))
    (if s
      (cons class (mapcan 'class-and-subclasses s))
      (list class))))

I'm not sure if this is a good solution or if one can think of a better way.

Any suggestions?


Thanks

Andreas

From: Marco Baringer
Subject: Re: (MOP) coding suggestion?
Date: 
Message-ID: <m27jgq3agj.fsf@soma.local>
"Andreas Thiele" <······@nospam.com> writes:

> I need a function which returns a list of all derived subclasses for a given
> class. It should contain the class itself. I wrote the following:
>
> (defun class-and-subclasses (class)
>   (let ((s (class-direct-subclasses class)))
>     (if s
>       (cons class (mapcan 'class-and-subclasses s))
>       (list class))))
>
> I'm not sure if this is a good solution or if one can think of a better way.
>
> Any suggestions?

looks fine to me.

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen
From: Pascal Bourguignon
Subject: Re: (MOP) coding suggestion?
Date: 
Message-ID: <877jgqo3r1.fsf@thalassa.informatimago.com>
"Marco Baringer" <··@bese.it> writes:

> "Andreas Thiele" <······@nospam.com> writes:
>
>> I need a function which returns a list of all derived subclasses for a given
>> class. It should contain the class itself. I wrote the following:
>>
>> (defun class-and-subclasses (class)
>>   (let ((s (class-direct-subclasses class)))
>>     (if s
>>       (cons class (mapcan 'class-and-subclasses s))
>>       (list class))))
>>
>> I'm not sure if this is a good solution or if one can think of a better way.
>>
>> Any suggestions?
>
> looks fine to me.

To me, it looks wrong:

[96]> (class-and-subclasses (find-class 'a))

*** - Lisp stack overflow. RESET


(defclass a () ())
(defclass b (a d) ())
(defclass c (b) ())
(defclass d (c) ())

Try rather:

[97]> (defun class-and-subclasses (class)
  (com.informatimago.common-lisp.utility:compute-closure
     (function class-direct-subclasses) (list class)))

CLASS-AND-SUBCLASSES
[98]> (class-and-subclasses (find-class 'a))
(#<STANDARD-CLASS A> #<STANDARD-CLASS B :INCOMPLETE>
 #<STANDARD-CLASS C :INCOMPLETE> #<STANDARD-CLASS D :INCOMPLETE>)
[99]> 

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
From: Marco Baringer
Subject: Re: (MOP) coding suggestion?
Date: 
Message-ID: <m2ll56zboq.fsf@soma.local>
Pascal Bourguignon <···@informatimago.com> writes:

> To me, it looks wrong:
>
> [96]> (class-and-subclasses (find-class 'a))
>
> *** - Lisp stack overflow. RESET
>
>
> (defclass a () ())
> (defclass b (a d) ())
> (defclass c (b) ())
> (defclass d (c) ())

this is a circular class hierarchy, isn't that reason enough to not
expect his code to deal with it? (what lisp lets you define those
clasess?)

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen
From: Andreas Thiele
Subject: Re: (MOP) coding suggestion?
Date: 
Message-ID: <d9407c$jpi$01$1@news.t-online.com>
"Pascal Bourguignon" <···@informatimago.com> schrieb im Newsbeitrag
···················@thalassa.informatimago.com...
> "Marco Baringer" <··@bese.it> writes:
>
> > "Andreas Thiele" <······@nospam.com> writes:
> >
> >> I need a function which returns a list of all derived subclasses for a
given
> >> class. It should contain the class itself. I wrote the following:
> >>
> >> (defun class-and-subclasses (class)
> >>   (let ((s (class-direct-subclasses class)))
> >>     (if s
> >>       (cons class (mapcan 'class-and-subclasses s))
> >>       (list class))))
> >>
> >> I'm not sure if this is a good solution or if one can think of a better
way.
> >>
> >> Any suggestions?
> >
> > looks fine to me.
>
> To me, it looks wrong:
>
> [96]> (class-and-subclasses (find-class 'a))
>
> *** - Lisp stack overflow. RESET
>
>
> (defclass a () ())
> (defclass b (a d) ())
> (defclass c (b) ())
> (defclass d (c) ())
>
> Try rather:
>
> [97]> (defun class-and-subclasses (class)
>   (com.informatimago.common-lisp.utility:compute-closure
>      (function class-direct-subclasses) (list class)))
>
> CLASS-AND-SUBCLASSES
> [98]> (class-and-subclasses (find-class 'a))
> (#<STANDARD-CLASS A> #<STANDARD-CLASS B :INCOMPLETE>
>  #<STANDARD-CLASS C :INCOMPLETE> #<STANDARD-CLASS D :INCOMPLETE>)
> [99]>
>
> --
> __Pascal Bourguignon__                     http://www.informatimago.com/

OK. Thanks for the hint. Fixing this like you explained is easy. But, I use
this function in conjunction with a metaclass which unfortunately does not
allow such circular inheritence. Now the question which makes me anxious is,
if there is any sensible application of such a circular inheritance?

Andreas
From: Kalle Olavi Niemitalo
Subject: Re: (MOP) coding suggestion?
Date: 
Message-ID: <878y16whw6.fsf@Astalo.kon.iki.fi>
Pascal Bourguignon <···@informatimago.com> writes:

> (defclass a () ())
> (defclass b (a d) ())
> (defclass c (b) ())
> (defclass d (c) ())

What would be the class precedence list of D?