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

Alexandre Rousseau yalexr at gmail.com
Fri Mar 10 08:18:32 PST 2023


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
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230310/77311ac4/attachment.htm>


More information about the Cuis-dev mailing list