Skip to main content
Engineering LibreTexts

5.1: Identifying Messages

  • Page ID
    39591
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    In Pharo, except for the syntactic elements listed in Chapter : Syntax in a Nutshell (:= ^ . ; # () {} [ : | ]<>), everything is a message send. There is no operators, just messages sent to objects. Therefore you can define a message named + in your class but there is also no precedence because Pharo always takes the simplest form of definition.

    The order in which messages are sent is determined by the type of message. There are just three types of messages: unary, binary, and keyword messages. Pharo distinguishes such three types of messages to minimize the number of parentheses. Unary messages are always sent first, then binary messages and finally keyword ones. As in most languages, parentheses can be used to change the order of execution. These rules make Pharo code as easy to read as possible. And most of the time you do not have to think about the rules.

    Message structure

    As most computation in Pharo is done by message passing, correctly identifying messages is key to avoiding future mistakes. The following terminology will help us:

    • A message is composed of the message selector and the optional message arguments.
    • A message is sent to a receiver.
    • The combination of a message and its receiver is called a message send as shown in Figure \(\PageIndex{1}\).
    Two message sends.
    Figure \(\PageIndex{1}\): Two message sends composed of a receiver, a method selector, and a set of arguments.

    A message is always sent to a receiver, which can be a single literal, a block or a variable or the result of evaluating another message.

    To help you identify the receiver of a message, we will underline it for you. We will also surround each message send with an ellipse, and number the message sends starting from the first one to help you see the send order in Figure \(\PageIndex{2}\).

    aMorph color: yellow message sends.
    Figure \(\PageIndex{2}\): aMorph color: Color yellow is composed of two message sends: Color yellow and aMorph color: Color yellow.

    Figure \(\PageIndex{2}\) represents two message sends, Color yellow and aMorph color: Color yellow, hence there are two ellipses. The message send Color yellow is executed first, so its ellipse is numbered 1. There are two receivers: 1) aMorph which receives the message color: ... and 2) Color which receives the message yellow. Both receivers are underlined.

    A receiver can be the first element of a message, such as 100 in the message send 100 + 200 or Color in the message send Color yellow. However, a receiver can also be the result of other messages. For example in the message Pen new go: 100, the receiver of the message go: 100 is the object returned by the message send Pen new. In all the cases, a message is sent to an object called the receiver which may be the result of another message send.

    Table \(\PageIndex{1}\): Message send characteristics.
    Message send Message type Action
    Color yellow unary Creates a color
    aPen go: 100 keyword Forwards pen 100 pixels
    100 + 20 binary 100 receives the message +
    Browser open unary Opens a new browser
    Pen new go: 100 unary and keyword Creates and moves pen 100 px
    aPen go: 100 + 20 keyword and binary Pen moves forward 120 px

    Table \(\PageIndex{1}\) shows several characteristics of message sends.

    • You should note that not all message sends have arguments. Unary messages like open do not have arguments. Single keyword and binary messages like go: 100 and + 20 each have one argument.
    • There are also simple messages and composed ones. Color yellow and 100 + 20 are simple: a message is sent to an object, while the message send aPen go: 100 + 20 is composed of two messages: + 20 is sent to 100 and go: is sent to aPen with the argument being the result of the first message.
    • A receiver can be an expression (such as an assignment, a message send or a literal) which returns an object. In Pen new go: 100, the message go: 100 is sent to the object that results from the execution of the message send Pen new.

    This page titled 5.1: Identifying Messages is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.