Is it really all about message passing in smalltalk

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 10:41:54

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 an Array, not a set) are certainly expressible otherwise, for example #(1 2 3) is equivalent to Array with: 1 with: 2 with: 3; they're just there to make the code easier to read and write.

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)

 exampleWithNumber: x

    | y |
    true & false not & (nil isNil) ifFalse: [self halt].
    y := self size + super size.
    #($a #a "a" 1 1.0)
        do: [ :each |
            Transcript show: (each class name);
                       show: ' '].
    ^x < y

Here's the comment for this method - which is larger than the method itself:

"A method that illustrates every part of Smalltalk method syntax except primitives. It has unary, binary, and keyboard messages, declares arguments and temporaries, accesses a global variable (but not an instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variables true, false, nil, self, and super, and has sequence, assignment, return and cascade. It has both zero argument and one argument blocks."

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!