Product SiteDocumentation Site

1.14. Message Instructions

You can send a message to an object to perform an action, obtain a result, or both. You use a message instruction if the main purpose of the message is to perform an action. You use a message term (see Section 1.11.4, “Message Terms”) if the main purpose of the message is to obtain a result.
A message instruction is a clause of the form:

>>-messageterm--+-------------+--;-----------------------------><
                +-=expression-+

If there is only a messageterm, the message is sent in exactly the same way as for a message term (see Section 1.11.4, “Message Terms”). If the message yields a result object, it is assigned to the sender's special variable RESULT. If you use the ~~ form of message term, the receiver object is used as the result. If there is no result object, the variable RESULT is dropped (becomes uninitialized). A message term using ~~ is sometimes referred to as a cascading message.

Example 1.34. Message instructions

mytable~add("John",123)

This sends the message ADD to the object MYTABLE. The ADD method need not return a result. If ADD returns a result, the result is assigned to the variable RESULT.
The equal sign (=) sets a value. If =expression follows the message term, a message is sent to the receiver object with an = concatenated to the end of the message name. The result of evaluating the expression is passed as the first argument of the message.

Example 1.35. Message instructions

person~age = 39                   /* Same as person~"AGE="(39) */
table[i] = 5                      /* Same as table~"[]="(5,i)  */

The expressions are evaluated in the order in which the arguments are passed to the method. That is, the language processor evaluates the =expression first. Then it evaluates the argument expressions within any [] pairs from left to right.
The extended assignment form may also be used with messaging terms.

Example 1.36. Message instructions

   table[i] += 1        -- Same as table[i] = table[i] + 1

See Section 1.13.1, “Extended Assignments” for more details