[Cuis-dev] What is the meaning of "::" in code examples ?
Luciano Notarfrancesco
luchiano at gmail.com
Fri Mar 10 10:20:11 PST 2023
The semicolon just cascades messages, I don’t see much mystery. You have a
message send, then after that you have semicolon and another message send
to the same receiver of the first message, and so on. The receiver of the
message after the semicolon is the same receiver of the last message before
the semicolon. It might be more clear looking at the bytecodes instead of
Smalltalk code.
On Fri, 10 Mar 2023 at 23:18 Alexandre Rousseau via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:
> 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> 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
>>
>>
>>
>>
>>
>>
>>
>> *From: *Alexandre Rousseau via Cuis-dev <cuis-dev at lists.cuis.st>
>> *Sent: *Friday, March 10, 2023 7:52
>> *To: *Discussion of Cuis Smalltalk <cuis-dev at lists.cuis.st>
>> *Cc: *Alexandre Rousseau <yalexr at gmail.com>; 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
>>
>>
>>
>>
>>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230311/8d7409c9/attachment.htm>
More information about the Cuis-dev
mailing list