最近我开始学习iolanguage。当尝试“方法”消息时,我写道:
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 会返回 nil 而不是 "f" 本身?
最佳答案
根据guide method()
引入一个对象来存储本地变量,并将本地变量的 self
指针设置为消息的目标。
因此,目标中没有插槽,但我们可以通过 self
获取它们:
Io> f := method(self getSlot("f"))
==> method(
self getSlot("f")
)
Io> f
==> method(
self getSlot("f")
)
关于iolanguage getSlot 未返回预期对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619802/