Smalltalk 中的消息传递真的都是这样吗?
我是 Smalltalk 的新手,该语言中只有 6 个关键字(self
、super
、true,
false
, nil
& thisContext
),以及几乎所有内容都作为消息传递的纯粹程度,例如。使用 whileTrue
进行循环,使用 ifTrue
进行 if/else 等...这与我在其他语言中习惯的方式有很大不同。
然而,在某些情况下,我无法理解消息传递的真正意义,其中包括:
- 赋值运算符
:=
- 级联运算符
;
- 句点运算符
>.
- 创建集合的方式
#( ... )
这些不是消息传递,对吗?
I'm new to Smalltalk and I'm impressed with the fact that there are only just 6 keywords in the language (self
, super
, true
, false
, nil
& thisContext
), and how pure it is in having almost everything as message passing, eg. looping using whileTrue
, if/else using ifTrue
, etc ... which are way different from what I'm used to in other languages.
Yet, there are cases where I just cannot make sense of how message passing really fit in, these include:
- the assignment operator
:=
- the cascading operator
;
- the period operator
.
- the way to create a set
#( ... )
These aren't message passing, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所发现的,仍然存在一些实际的 Smalltalk 语法。块构造、文字字符串/符号/注释、局部变量声明 (
|...|
) 和返回 (^
) 是您没有提到的一些内容也是语法。某些扩展(例如
#(...)
,通常创建一个Array
,而不是集合)当然可以以其他方式表达,例如#(1 2 3 )
相当于Array with: 1 with: 2 with: 3
;它们只是为了让代码更容易阅读和编写。As you've discovered, there's still some actual Smalltalk syntax. Block construction, literal strings/symbols/comments, local variable declaration (
|...|
), and returning (^
) are a few things you didn't mention which are also syntax.Some extensions (e.g.
#(...)
, which typically creates anArray
, not a set) are certainly expressible otherwise, for example#(1 2 3)
is equivalent toArray with: 1 with: 2 with: 3
; they're just there to make the code easier to read and write.一件事可能有助于澄清:
self
、super
、true
、false
、nil
> &thisContext
是数据原语,而不是关键字。它们是仅有的 6 个数据原语。这 6 个变量也称为伪变量。绝对所有其他事物都是类对象或其子类的实例。
Smalltalk 中预定义的关键字很少。它们可以以非常简洁的形式编写。
一个著名的例子是 Smalltalk Syntax on a Postcard (link)
这是此方法的注释 - 这是大于方法本身:
One thing that might help clarify :
self
,super
,true
,false
,nil
&thisContext
are data primitives, rather than keywords.They are the only 6 data primitives. These 6 are also known as pseudo-variables. Absolutely every other thing is an instance of Class Object or its subclasses.
There are very few pre-defined keywords in Smalltalk. They can be written in a very condensed form.
A famous example is Smalltalk Syntax on a Postcard (link)
Here's the comment for this method - which is larger than the method itself: