Chapter 5. Expressions and operators

Operators in PPL

PPL provides the following operators:

Arithmetic+, -, *, /
Booleanand, or, xor, not
Comparison>, >=, <, <=
Value equality=v, #v
Reference equality=r, #r
Feature access., .null?, .error?
if expressionif {expression} then {expression} else {expression} end if
Null alternativeif_null:
Error alternativeif_error:

Common precedence rules are built into PPL (e.g. multiplication before addition).

Some operators represent a short-cut for a command. For example, the compiler applies command multiply for operator *. Thus 3 * 4 is translated by the compiler to 3.multiply(4).

Therefore you can use these operators for your own types if they implement the command associated with the operator. For example, if you create a new type complex_number with commands add and multiply, you can use the operators + and * and benefit from the built-in operator precedence rules. Instead of writing ...

c4 = c2.multiply(c3).add(c1)

.. you can simply write:

c4 = c1 + c2 * c3

The following table shows the built-in command names for operators that can be used in your own types:

OperatorCommand name
=v, #vis_equal_to
>, >=, <, <=compare_to

Examples of expressions and operators: