例子:
st> [ fnord := 7 ] value
我一直觉得他们在 进入 SystemDictionary Smalltalk
,但事实并非如此:
st> [ fnord := 7 ] value
st> Smalltalk at: #fnord
Object: SystemDictionary new: 512 "<0x2acfca382030>" error: Invalid argument #fnord: key not found
然而,至少在 GNU Smalltalk 上,这些值似乎被保留在某个地方——访问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
所以它肯定认为它正在写入一个全局变量。