在吱吱声中创建新的伪变量

时间:2010-05-18 22:45:09

标签: variables smalltalk squeak

大部分吱吱声是使用吱吱声本身实现的。我很想知道是否使用squeak实现了诸如selftrue之类的伪变量。如果答案是肯定的,那么实施位于何处?

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

有什么想法吗? 谢谢。

2 个答案:

答案 0 :(得分:4)

让它成为一个全球性的:

Smalltalk at: #other put: Other new

答案 1 :(得分:1)

如果没有对Smalltalk图像进行进一步修改,之前的答案将无效,因为布尔会覆盖新的以引发错误

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

如果您尝试使用布尔子类:#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).
相关问题