In this session, I'll mention two points:
sequence and cascade, which are very common in Pharo.
There are often several expressions in a row.
They must be separated.
You do that with a period as in the example.
Here you have: Transcript cr and a period.
The transcript is a small tool for log messages.
I want a new line. I want to show the object 1.
I want to show 2. I could or couldn't have used a period.
The expressions are separated by periods.
Let's see another example.
I've defined two local variables.
I define a workstation, which is a network simulator.
I write a period as it's the end of this expression.
I continue with the next expression. I could have used a period here.
As I explained, a period is a separator, not a terminator.
In Java, you must use a semicolon here and there.
In Pharo, you don't have to.
What can be a bit strange for beginners
is that pipes are definitions of local variables.
There'll be a lesson about this.
You don't use a period here.
Usually, you define the local variable. Then you start.
After the first expression, you use a period.
There's something else:
you'd often like to send several messages to the same object.
But since we're lazy, we don't want to repeat the receiver.
Look at this:
I write Transcript cr. Transcript show: Transcript...
I already said transcript three times instead of once.
I can do it: I'll use a cascade, the semicolon.
I write: Transcript cr;
I send the message cr to the object transcript.
The cascade says:
"From now on, all messages are sent to the same receiver as the first."
It means show 1 is sent to Transcript
and show 2 to Transcript.
I'll say this again as it's unusual.
I send the first message normally.
Instead of using a period, which is a separator, I use a semicolon.
It means every other message must be sent to the same receiver.
show: 1 is sent to same receiver.
A semicolon means: show: 2 is sent to the same receiver.
Another example: imagine you want to create a collection.
I have a collection, so I define a variable c.
I write the collection in c. See the period here?
I add 1 and 2 to the collection.
These two expressions are exactly the same.
It means I write: OrderedCollection new
I create it then add the first message add: 1 to add an element.
The semicolon means this message must be sent to this collection.
As Pharo beginners, I'd advise you
not to bother using the cascade.
I introduced it because you'll read code.
People use it in code.
When you feel comfortable with this syntax and with periods,
you can start to think you can be a bit more flexible
and use the cascade. That's how I learned.
Just go step by step.
What did we study?
. is a separator. It's the same as ; in Java.
; is a cascade which is useful to avoid repeating the same receiver.
The cascade returns the value of the last message sent.