Monadic operators
Keywords: pame

#
Monadic operators

Operators come in two flavours: monadic and dyadic. A monadic operator has only one operand, but a dyadic operator has two operands. A monadic operator is written before its operand. For example, the monadic minus `-` reverses the sign of its operand:

       -3000

This could equally well be written `- 3000` since spaces are, generally speaking, not significant. There is, likewise, a monadic `+` operator which doesn't do anything to its operand, but is useful where you want to refer expressly to a positive number. It has been provided for the sake of consistency. You should note that `-3000` is not a denotation, but a formula consisting of a monadic operator operating on an operand which is a denotation. We say that the monadic operator `-` takes an operand of mode `INT` and yields a value of mode `INT`. It can also take an operand of mode `REAL` when it will yield a value of mode `REAL`.

A formula can be used as the value part of an identity declaration. Thus the following identity declarations are both valid:

       INT  minus 2 = -2;
       REAL minus point five = -0.5

The operator `ABS` takes an operand of mode `INT` and yields the absolute value again of mode `INT`. For example, `ABS -5` yields the value denoted by `5`:

       INT five = ABS -5

Note that when two monadic operators are combined, they are elaborated in right-to-left order, as in the above example. That is, the `-` acts on the `5` to yield `-5`, then the `ABS` acts on `-5` to yield `+5`. This is just what you might expect. `ABS` can also take an operand of mode `REAL` yielding a value of mode `REAL`. For example:

       REAL x = -1.234;
       REAL y = ABS x

Another monadic operator which takes an `INT` operand is `SIGN`. This yields -1 if the operand is negative, 0 if it is zero, and +1 if it is positive. Thus you can declare

       INT res = SIGN i

if i has been previously declared.