Smalltalk priority rules - this is the first: unary messages
second: binary messages
third: keyword messages
last: left to right
This order can be changed from left to right using parentheses (for example, parentheses). First, the expression inside the pair of brackets is evaluated. If the inserts are copied, the evaluation of the innermost bracket is first performed, then it goes out to the outer bracket and, finally, the remainder of the expression outside the brackets.
Due to the strong trend from left to right, I often find it helpful to read the expression from right to left.
So, for [(line := self upTo: Character cr) size = 0] whileTrue.
Approaching from the end to the beginning, we get the following interpretation.
. Complete the expression. Equivalent in C or Java
whileTrue What's immediately to his left? ] closing the block object.
So, whileTrue is a unary message sent to the block [ ... ] ie keep doing this block while the block evaluates to true
The block returns the result of the last expression evaluated in the block.
The last expression in the block size = 0 comparison. And a binary message.
size usually a unary message sent to the recipient. So, we check the size of something to see if it is 0 . If something has a size of 0 , keep moving.
What do we check size ? The expression immediately to the left of the message name. To the left of size is (line := self upTo: Character cr)
This is what we want to know by size.
So, time to put this expression under the knife.
(line := self upTo: Character cr) - task. line will have the result self upTo: Character cr .
What is at the right end of this expression? cr This is a unary message, therefore has the highest priority. What is he going to. that is, what is the receiver for the cr message?
Immediately on the left is Character . So send the Character class a cr message. This evaluates to an instance of the Character class with a value of 13 — that is, a carriage return character.
So now we get to self upTo: aCarriageReturn
If self - the object receiving the message self upTo: aCarriageReturn - does not understand the name of the message sizeUpto: it throws an exception.
So, if this is code from a working system, we can conclude that self should be an object that understands sizeUpto: At this point, I am often tempted to find a massage name to see which classes have a message called sizeUpto: in the list of message names that they know and understand (i.e. their message protocol).
(In this case, it did not help me - it is not a method in any of the classes of my Smalltalk system).
But self seems to be asked to deal with a character string containing (potentially) many many carriage returns.
So, return the first part of aCharacterString with respect to the first carriage return.
If the length of aCharacterString from the beginning to the first carriage return is zero, continue moving and do it all again.
So, it seems that we are dealing with concatenation of several lines with cr-terminated and process each one in turn until we find one that is not empty (except for carriage return) and assigns it line