2014-02-07 51 views
2

最近我開始學習iolanguage。當試圖走出「方法」消息,我寫道:iolanguage getSlot不返回預期的對象

Io> f := method(getSlot("f")) 
==> method(
    getSlot("f") 
) 

Io> slotSummary 
==> Object_0x97f41a8: 
    Lobby   = Object_0x97f41a8 
    Protos   = Object_0x97f4090 
    _    = nil 
    exit    = method(...) 
    f    = method(...) 
    forward   = method(...) 
    set_    = method(...) 

Io> f 
==> nil 

但爲什麼打電話到f將返回而不是「F」本身?

回答

2

根據guidemethod()介紹了一個對象來存儲當地人和設置本地的self指針消息的目標。 因此沒有來自目標的插槽,但我們可以通過它們獲得它們self

Io> f := method(self getSlot("f")) 
==> method(
    self getSlot("f") 
) 
Io> f 
==> method(
    self getSlot("f") 
) 
0

嘗試g := block(getSlot("g")),它應該做你期望的。不幸的是,我無法解釋爲什麼會這樣 - 對不起。我想這與blockmethod以不同方式設置selfproto指針有關。

您可以在method或以上嘗試以下操作。 block和比較結果:

call sender   #locals object of caller 
call message   #message used to call this method/block 
call activated  #the activated method/block 
call slotContext  #context in which slot was found 
call target   #current object