2015-09-13 34 views
2

爲什麼我無法在sbcl中獲得簡單的類優先級列表?獲取類優先級列表時的未綁定槽位?

* (sb-mop::class-precedence-list (find-class 'cons));;works 

(#<BUILT-IN-CLASS CONS> #<BUILT-IN-CLASS LIST> #<SB-PCL:SYSTEM-CLASS SEQUENCE> 
#<SB-PCL:SYSTEM-CLASS T>) 
* (defclass my-class() nil) 
* (sb-mop::class-precedence-list (find-class 'my-class)) 

debugger invoked on a UNBOUND-SLOT in thread 
#<THREAD "main thread" RUNNING {10039CE8D3}>: 
    The slot SB-PCL::%CLASS-PRECEDENCE-LIST is unbound in the object 
    #<STANDARD-CLASS MY-CLASS>. 

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL. 

restarts (invokable by number or by possibly-abbreviated name): 
    0: [USE-VALUE ] Return a value as the slot-value. 
    1: [STORE-VALUE] Store and return a value as the slot-value. 
    2: [ABORT  ] Exit debugger, returning to top level. 

((:METHOD SLOT-UNBOUND (T T T)) #<unavailable argument> #<STANDARD-CLASS MY-CLASS> SB-PCL::%CLASS-PRECEDENCE-LIST) [fast-method] 
0] 2 

回答

4

類定稿

從拖把描述:

類定稿是計算類從其超類繼承的信息,並準備實際分配的類的實例的過程。類定型過程包括計算類的類優先級列表,可在類的實例中訪問的全套插槽以及類的全部默認初始化參數。這些值與類元對象相關聯,可通過調用適當的閱讀器進行訪問。此外,班級最終確定過程將決定如何實施班級實例。

爲了支持向前引用超類,並且考慮一個事實,即並非所有的類被實例化,類定稿不作爲類元對象的初始化的一部分來完成。相反,finalization是作爲一個單獨的協議完成的,通過調用通用函數finalize-inheritance來調用。調用finalize繼承的確切點取決於類元對象的類;對於標準類,它在所有類超類被定義之後的某個時候被調用,但不晚於當類的第一個實例被分配時(通過allocate-instance)。

類定型的第一步是計算類優先級列表。這樣做首先允許後續步驟訪問類優先級列表。這一步通過調用泛型函數compute-class-precedence-list來執行。此調用返回的值與類元對象關聯,並且可以通過調用class-precedence-list通用函數來訪問。

...

* (defclass my-class() nil) 

#<STANDARD-CLASS MY-CLASS> 
* (sb-mop:class-finalized-p (find-class 'my-class)) 

NIL 
* (sb-mop:finalize-inheritance (find-class 'my-class)) 

NIL 
* (sb-mop:class-finalized-p (find-class 'my-class)) 

T 
* (sb-mop:class-precedence-list (find-class 'my-class)) 

(#<STANDARD-CLASS MY-CLASS> #<STANDARD-CLASS STANDARD-OBJECT> 
#<SB-PCL::SLOT-CLASS SB-PCL::SLOT-OBJECT> #<SB-PCL:SYSTEM-CLASS T>)