Product SiteDocumentation Site

1.11.5. Message Sequences

The ~ and ~~ forms of message terms differ only in their treatment of the result object. Using ~ returns the result of the method. Using ~~ returns the object that received the message. Here is an example:

Example 1.19. Messages

/* Two ways to use the INSERT method to add items to a list */
/* Using only ~ */
team = .list~of("Bob","Mary")
team~insert("Jane")
team~insert("Joe")
team~insert("Steve")
say "First on the team is:" team~firstitem     /* Bob   */
say "Last on the team is:" team~lastitem       /* Steve */
/* Do the same thing using ~~ */
team=.list~of("Bob","Mary")
/* Because ~~ returns the receiver of the message       */
/* each INSERT message following returns the list       */
/* object (after inserting the argument value).         */
team~~insert("Jane")~~insert("Joe")~~insert("Steve")
say "First on the team is:" team~firstitem     /* Bob   */
say "Last on the team is:" team~lastitem       /* Steve */

Thus, you would use ~ when you want the returned result to be the receiver of the next message in the sequence.