[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

correct way to find class precedence list

Jim Newton

3/30/2016 9:13:00 AM

If I define several classes in an inheritance chain, then call class-precedence-list
I'm liable to find that the classes have not yet been finalized, which triggers
an error.

The slot SB-PCL::%CLASS-PRECEDENCE-LIST is unbound in the object
#<STANDARD-CLASS COMMON-LISP-USER::C>.
[Condition of type UNBOUND-SLOT]

However if I call compute-class-precedence-list it is unnecessary if the
class has indeed already been finalized. My reading of compute-class-precedence-list
specification is that it RE-compuates the list even if class-precedence-list already
contains the correct value.

What is the correct way to dependably and efficiently find the class precedence list of a class?


6 Answers

Elias Mårtenson

3/30/2016 4:40:00 PM

0

You should call FINALIZE-INHERITANCE on the class before calling CLASS-PRECEDENCE-LIST on it.

Pascal Costanza

4/2/2016 11:29:00 AM

0

On 30/03/16 18:40, Elias Mårtenson wrote:
> You should call FINALIZE-INHERITANCE on the class before calling CLASS-PRECEDENCE-LIST on it.

Before calling finalize-inheritance, you should check if it's already
finalized. If so, don't call finalize-inheritance again - I recall at
least one implementation choking on calls to finalize-inheritance on
classes that are already finalized.

You could also call make-instance on the class metaobject instead, but
that's quite heavy-weight.

Pascal

--
My website: http:/...
Common Lisp Document Repository: http://cdr.eu...
Closer to MOP & ContextL: http://common-lisp.net/proje...
The views expressed are my own, and not those of my employer.

Elias Mårtenson

4/3/2016 12:06:00 PM

0

On Saturday, 2 April 2016 19:29:32 UTC+8, Pascal Costanza wrote:
> On 30/03/16 18:40, Elias Mårtenson wrote:
> > You should call FINALIZE-INHERITANCE on the class before calling CLASS-PRECEDENCE-LIST on it.
>
> Before calling finalize-inheritance, you should check if it's already
> finalized. If so, don't call finalize-inheritance again - I recall at
> least one implementation choking on calls to finalize-inheritance on
> classes that are already finalized.

Which implementation is that? Also, for that implementation, wouldn't it make sense for CLOSER-MOP to handle that check?

Pascal Costanza

4/3/2016 2:27:00 PM

0

On 03/04/16 14:05, Elias Mårtenson wrote:
> On Saturday, 2 April 2016 19:29:32 UTC+8, Pascal Costanza wrote:
>> On 30/03/16 18:40, Elias Mårtenson wrote:
>>> You should call FINALIZE-INHERITANCE on the class before calling CLASS-PRECEDENCE-LIST on it.
>>
>> Before calling finalize-inheritance, you should check if it's already
>> finalized. If so, don't call finalize-inheritance again - I recall at
>> least one implementation choking on calls to finalize-inheritance on
>> classes that are already finalized.
>
> Which implementation is that?

I don't remember which implementation that was, it's too long ago I last
checked.

Also, it doesn't actually matter which implementation this is, because
there is nothing in the CLOS MOP specification that guarantees that you
can call finalize-inheritance multiple times, so strictly speaking, an
implementation can choose not to allow this anyway.

(Class reinitialization invokes finalize-inheritance again, but that
doesn't mean anyone can call finalize-inheritance again.)

> Also, for that implementation, wouldn't it make sense for CLOSER-MOP to handle that check?

closer-mop already provides ensure-finalized for this purpose,
independent of implementation.

Pascal

--
My website: http:/...
Common Lisp Document Repository: http://cdr.eu...
Closer to MOP & ContextL: http://common-lisp.net/proje...
The views expressed are my own, and not those of my employer.

Jim Newton

4/4/2016 7:49:00 AM

0

So are you suggesting I simply call ensure-finalized before calling class-precedence-list?

On Sunday, April 3, 2016 at 4:26:51 PM UTC+2, Pascal Costanza wrote:
> closer-mop already provides ensure-finalized for this purpose,
> independent of implementation.

Pascal Costanza

4/9/2016 11:52:00 AM

0

On 04/04/16 09:48, Jim Newton wrote:
> So are you suggesting I simply call ensure-finalized before calling class-precedence-list?
>

Yes, I guess that should work.

Pascal

--
My website: http:/...
Common Lisp Document Repository: http://cdr.eu...
Closer to MOP & ContextL: http://common-lisp.net/proje...
The views expressed are my own, and not those of my employer.