jayven huangjunwen
jayven huangjunwen

Reputation: 780

iolanguage getSlot does not return expected object

Recently i started to learn iolanguage. When trying out the "method" message, i wrote:

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

But why calling to f will return nil instead of "f" itself?

Upvotes: 2

Views: 153

Answers (2)

user2422869
user2422869

Reputation: 760

According to guide method() introduces an Object to store locals and sets the local's self pointer to the target of the message. Thus there is no slots from target but we can get them through self:

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

Upvotes: 2

phimuemue
phimuemue

Reputation: 36081

Try g := block(getSlot("g")), which should do what you expect. Unfortunately, I can not explain why this is the case - sorry. I suppose it has to do with the fact that block and method set the self and proto pointer in different ways.

You can try the following within a method resp. block and compare the results:

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

Upvotes: 0

Related Questions