2

squeak 的很大一部分是使用 squeak 本身实现的。我很想知道诸如self或之类的伪变量true是否也使用吱吱声来实现。如果答案是肯定的,那么实施在哪里?

具体来说,假设我想添加名为“Other”的“Boolean”的新子类,这将代表第三个选项:既不是真也不是假。我想要那个other,唯一Other类似于真/假全局单例的实例。

有任何想法吗?谢谢你。

4

2 回答 2

4

使其成为全球性的:

Smalltalk at: #other put: Other new
于 2010-05-19T06:32:57.827 回答
1

如果不进一步修改您的 Smalltalk 图像,之前的答案将无法工作,因为布尔值会覆盖 new 以引发错误

new
    self error: 'You may not create any more Booleans - this is two-valued logic'

如果您尝试 Boolean subclass: #Other 然后尝试将 other 关键字添加到 Smalltalk 全局变量中,您将引发错误。

您可以删除 Boolean>>new,实现您的 Other 类,将其添加到 Smalltalk 全局变量中,然后替换 Boolean>>new。

接下来,您可能会考虑更新 ClassBuilder>reservedNames 以保护您的新布尔值

reservedNames
"Return a list of names that must not be used for variables"
    ^#('self' 'super' 'thisContext' 'true' 'false' 'nil' 
     self super thisContext #true #false #nil).
于 2013-07-15T06:15:00.057 回答