示例:
st> [ fnord := 7 ] value
我一直觉得他们进入了SystemDictionary at Smalltalk
,但事实并非如此:
st> [ fnord := 7 ] value
st> Smalltalk at: #fnord
Object: SystemDictionary new: 512 "<0x2acfca382030>" error: Invalid argument #fnord: key not found
但是,至少在GNU上,这些值似乎是持久化的--访问fnord
返回正确的值:
st> [ fnord := 7 ] value
st> fnord
7
更新:我想出了如何拆解块!这真的很难。
st> [ fnord := 7 ] block inspect
An instance of CompiledBlock
header: 32768
clean-ness flags: 0
number of arguments: 0
number of temporaries: 0
number of literals: 4
needed stack slots: 8
method: UndefinedObject>>executeStatements
literals: [
[1] {fnord}
[2] a BlockClosure
[3] #block
[4] #inspect
]
byte codes: [
[1] source code line number 1
[3] push 7
[5] store into Global Variable {fnord}
[7] pop stack top
push Global Variable {fnord}
[9] return stack top
]
[] in UndefinedObject>>executeStatements
所以它肯定认为它是在写一个全局变量。
发布于 2015-09-07 11:19:39
未声明的变量绑定进入名为Undeclared
的全局字典。一旦正确声明绑定( key->value
对),该绑定将被移动到Smalltalk
。例如,这就是在加载代码时如何解析前向引用。也就是说,在声明变量的代码加载之前使用变量。
https://stackoverflow.com/questions/32422622
复制相似问题