Chapter 3 The Application Description Language

3.13 Messages

A message is an operation that one object performs upon another. You can send a message to any object. It consists of three parts:

1. Selector (message name): The string identifier for the message must have a match in the receiving object's method dictionary.

2. Message arguments: Arguments are optional. The message selector and any arguments form the message list.

3. Message target: A reference to an object, or to the handle of an object, that is to receive the message list.
Sample Messages
'Construct => Viewer;
'Init?=> Viewer;
{mName} + {"width", 40} |> myTarget;
dayMonth = 'GetDayOfMonth => Calendar

The target object method has the option to return a value. If a method returns a value in some cases, it must return a value in all cases. The returned value may be unset. Messages that return a value can appear in expressions. Messages that do not return a value must appear in standalone statements.

If there are no message arguments, the message list can consist of a string. Otherwise, the message list must be a true list whose first element is a string specifying the message selector. The message list can be a list variable or a list valued expression. It is evaluated at run-time just before the message is sent so that all parts of the message, including the selector, are dynamic. A message argument may be unset.

One of the following message operators separates the message list and the message target:(=>),(|>),(?=>),and (?|>). The operators (=>) and (?=>) specify that the message is to be sent synchronously -- that is, the message is sent immediately and the invoked method is executed before the next statement in the calling method. A synchronous message thus effectively creates a new stack frame. The operators (|>) and (?|>) conversely specify that the message is to be sent asynchronously --that is, the message is queued for later delivery. The system guarantees that an asynchronous message will be delivered and executed before the return to the overall event loop if an appropriate method exists in the destination object. No guarantees are made, however, about the relative execution of multiple asynchronous messages.

The operators (?=>) and (?|>) send optional messages, while the operators (=>) and (|>) send required messages. It is an error to send a required message to an object that does not possess a method for the message selector. If an object receives an optional message with a selector that it does not understand, however, it simply ignores the message. Optional messages are particularly useful for broadcasting system messages to all objects.

Since message arguments are passed as members of a list, they must be passed by value. No object can be a member of a list, and thus, no object can be an argument to a message. A handle to an object, however, can be passed as an argument to a message. The return value, if present, must also be one of the base or compound system types and is also passed by value. A message cannot return an object or a complex data type (i.e., indexed or associative arrays).


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker