Product SiteDocumentation Site

1.11.2. Operators

An operator is a representation of an operation, such as an addition, to be carried out on one or two terms. Each operator, except for the prefix operators, acts on two terms, which can be symbols, strings, function calls, message terms, intermediate results, or subexpressions. Each prefix operator acts on the term or subexpression that follows it. Whitespace characters (and comments) adjacent to operator characters have no effect on the operator; thus, operators constructed from more than one character can have embedded whitespace and comments. In addition, one or more whitespace characters, if they occur in expressions but are not adjacent to another operator, also act as an operator. The language processor functionally translates operators into message terms. For dyadic operators, which operate on two terms, the language processor sends the operator as a message to the term on the left, passing the term on the right as an argument. For example, the sequence
say 1+2
is functionally equivalent to:
say 1~"+"(2)
The blank concatenation operator sends the message " " (a single blank), and the abuttal concatenation operator sends the "" message (a null string). When the ¬ character is used in an operator, it is changed to a \. That is, the operators ¬= and \= both send the message \= to the target object.
For an operator that works on a single term (for example, the prefix - and prefix + operators), Rexx sends a message to the term, with no arguments. This means -z has the same effect as z~"-".
See Section 5.1.1.2, “Operator Methods” for operator methods of the Object class and Section 5.1.3.7, “Arithmetic Methods” for operator methods of the String class.
There are four types of operators:
  • Concatenation
  • Arithmetic
  • Comparison
  • Logical

1.11.2.1. String Concatenation

The concatenation operators combine two strings to form one string by appending the second string to the right-hand end of the first string. The concatenation may occur with or without an intervening blank. The concatenation operators are:
(blank)
Concatenate terms with one blank in between
||
Concatenate without an intervening blank
(abuttal)
Concatenate without an intervening blank
You can force concatenation without a blank by using the || operator.
The abuttal operator is assumed between two terms that are not separated by another operator. This can occur when two terms are syntactically distinct, such as a literal string and a symbol, or when they are only separated by a comment.
Examples:
An example of syntactically distinct terms is: if Fred has the value 37.4, then Fred"%" evaluates to 37.4%.
If the variable PETER has the value 1, then (Fred)(Peter) evaluates to 37.41.
The two adjoining strings, one hexadecimal and one literal, "4a 4b"x"LMN" evaluate to JKLMN.
In the case of
Fred/* The NOT operator precedes Peter. */¬Peter
there is no abuttal operator implied, and the expression is not valid. However,
(Fred)/* The NOT operator precedes Peter. */(¬Peter)
results in an abuttal, and evaluates to 37.40.