【问题标题】:Create New Pseudo Variables in Squeak在 Squeak 中创建新的伪变量
【发布时间】:2010-05-18 22:45:08
【问题描述】:

squeak 的很大一部分是使用 squeak 本身实现的。我很想知道selftrue 等伪变量是否也使用squeak 实现。如果答案是肯定的,那么实现在哪里?

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

有什么想法吗? 谢谢。

【问题讨论】:

    标签: variables smalltalk squeak


    【解决方案1】:

    使其成为全球性的:

    Smalltalk at: #other put: Other new
    

    【讨论】:

      【解决方案2】:

      如果不对您的 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).
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-18
        • 2011-03-10
        • 2011-08-17
        • 1970-01-01
        • 2020-01-16
        • 1970-01-01
        相关资源
        最近更新 更多