📜 ⬆️ ⬇️

Smalltalk syntax note

image
Hello!

In the comments to the topic, people were interested in the Smalltalk brand features. This note would like to slightly disclose the comment of the user mou and put the main emphasis on the simplicity of the language.

In order to program using the Smalltalk language, it’s enough to know 2 concepts:

In addition, you can send a message to the class itself, since the class, in turn, is also an instance ( Chicken or egg? ).
It should be noted that the language supports:

With the help of the message sending mechanism, all operations familiar to programming languages ​​are implemented: loops, conditional jumps, etc.
Messages sent to an object (class instance) can be of three types:


As an example, I will give the method of processing a binary message * which multiplies the receiver matrix by the argument matrix:
')
* rcMatrix
" "

" "
| r |
" r new:with: RCMatrix"
r := RCMatrix new: (self rowsCount) with: (rcMatrix columnsCount).

" "
1 to: (self rowsCount) do:
[:i |
1 to: (rcMatrix columnsCount) do:
[:j |
r at: i at: j put: 0.
].
].

""
1 to: (self rowsCount) do:
[:i |
1 to: (rcMatrix columnsCount) do:
[:j |
1 to: (rcMatrix rowsCount) do:
[:k |
r at: i at: j put:
((r at: i at: j) +
((self at: i at: k) * (rcMatrix at: k at: j))).
].
].
].

" "
^r.


* This source code was highlighted with Source Code Highlighter .


Thank you for your attention to the note.

Source: https://habr.com/ru/post/72007/


All Articles