[Cuis-dev] What is the meaning of "::" in code examples ?

Jaromir Matas mail at jaromir.net
Fri Mar 10 10:18:29 PST 2023


> Perhaps, rephrase "Semicolons can be used to send a cascade of messages to the original receiver" to "Semicolons can be used to send a cascade of messages to the closest sender"? This may be truer but the term "closest sender" is confusing; closest to what?

"sender" has a distinct meaning; it's a context that initiated sending of a message but this can't be used here.

I would revert the wording to the original wording in Squeak by Example (aka SBE, see page 52 of Edition 5.3):

"Semicolons can be used to send a cascade of messages to a single receiver. [...]"

Or, possibly, include a more explicit explanation (also from the SBE):
Smalltalk offers a way to send multiple messages to the same receiver using a semicolon (;). This is called the cascade in Smalltalk jargon. The receiver is specified just once, and the sequence of messages is separated by semi-colons.


Double-colon is not, strictly speaking, "cascading" but rather chaining messages (or we can just accept an extended meaning of "cascade").

Thanks to the precedence rules we can chain unary messages without any further syntactic means:
#(1 2 3) squared max negated

In order to be able to do the same with keyword messages the double-colon has been added to the compiler:
#(1 2 3) raisedTo: 2 :: max: [:x|x] :: negated


--

Jaromír Matas
mail at jaromir.net


From: Alexandre Rousseau<mailto:yalexr at gmail.com>
Sent: Friday, March 10, 2023 17:18
To: Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>
Cc: Jaromir Matas<mailto:mail at jaromir.net>; jhylands at gmail.com<mailto:jhylands at gmail.com>
Subject: Re: [Cuis-dev] What is the meaning of "::" in code examples ?

It's a nice nuance.

#(1 2 3) negated select: #odd; collect: #cubed. #(-1 -8 -27)
#(1 2 3) negated; select: #odd; collect: #cubed. #(1 8 27)

Perhaps, rephrase "Semicolons can be used to send a cascade of messages to the original receiver" to "Semicolons can be used to send a cascade of messages to the closest sender"? This may be truer but the term "closest sender" is confusing; closest to what?

On Fri, Mar 10, 2023 at 10:23 AM Jaromir Matas <mail at jaromir.net<mailto:mail at jaromir.net>> wrote:
Hi Alexandre, Jon,

> Semicolons can be used to send a cascade of messages to the original receiver.

Note it’s not immediately clear what the “original receiver” is (at least to me); check this:

#(1 2 3) negated select: #odd; collect: #cubed "---> #(-1 -8 -27)"

The “original receiver” is the result of `#(1 2 3) negated` and not `#(1 2 3)` as one might think.

In light of this the quoted example `BoxedMorph new :: color: Color blue; openInWorld.` is misleading, imo, because it suggests the double colon is relevant here but it’s not: this gives the same result:

BoxedMorph new color: Color blue; openInWorld.

> It is sometimes useful to send messages to the result of a message send.

Each message is sent to the result of the previous message send by default (taking precedence into account indeed). The double colon effectively separates the keyword messages so that they act similarly like unary messages when chained:

#(1 2 3) negated select: #odd :: collect: #cubed "---> #(-1 -27)"

I think a more relevant BoxedMorph example would be (whether meaningful or not):

BoxedMorph newFrom: BoxedMorph new :: color: Color blue; openInWorld.

This wouldn’t work without the double colon.

Best,
Jaromir


--

Jaromír Matas
mail at jaromir.net<mailto:mail at jaromir.net>



From: Alexandre Rousseau via Cuis-dev<mailto:cuis-dev at lists.cuis.st>
Sent: Friday, March 10, 2023 7:52
To: Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>
Cc: Alexandre Rousseau<mailto:yalexr at gmail.com>; jhylands at gmail.com<mailto:jhylands at gmail.com>
Subject: Re: [Cuis-dev] What is the meaning of "::" in code examples ?

 Thanks for the link.

* Cascades
There are two kinds of message cascades.

Semicolons can be used to send a cascade of messages to the original
receiver. In "Transcript show: 'hello'; cr" we first send the keyword
message #show: 'hello' to the receiver Transcript, and then we send
the unary message #cr to the same receiver.

It is sometimes useful to send messages to the result of a message
send. In "BoxedMorph new :: color: Color blue; openInWorld.", we send
succeeding messages to the new BoxedMorph instance, not the BoxedMorph
class.

So,
lay1 beRow :: borderWidth: 1 :: borderColor: (Color black) .

can also be expressed as
lay1 beRow; borderWidth: 1; borderColor: (Color black).
since all messages are intended for the original receiver (lay1).

And since "beRow" also returns the original object (lay1),
lay1 beRow :: borderWidth: 1 :: borderColor: (Color black) .
works as well.

A.

> According to this page:
>
> https://cuis-smalltalk.github.io/TheCuisBook/Summary-of-Syntax.html
>
> Double-colon sends the message to the result of the previous expression. I
> would guess that would make it functionally equivalent to putting the
> previous expression in parens.
>
> So:
>
> lay1 beRow :: borderWidth: 1 :: borderColor: (Color black) .
>
> would be the same as:
>
> ((lay1 beRow) borderWidth: 1) borderColor: (Color black) .
>
> Unless I'm missing something...
>
> - Jon



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230310/eabbf463/attachment-0001.htm>


More information about the Cuis-dev mailing list