[Next] [Prev] [Right] [Left] [Up] [Index] [Root]
Operators

Operators

An operator is a symbol used for combining expressions to make larger expressions. Examples of operators are the exponentiation and multiplication operators + and * in (3 + 8) * 26. Most operators are binary, because they act on two operands, but a few, such as - in the expression -15, are unary.

The arithmetic operators are + - * / div mod ^ .

Technically, a Magma operator is an infix function. That is, it is a function on its operands which is put between the two operands instead of before the two comma-separated operands enclosed in parentheses. (In the case of unary operators, the operator is placed immediately before the operand, again with no parentheses required.)

Any operator can be treated like a normal function by enclosing it in ' marks. For instance:

> print 'div'(100, 13);
7
> print '-'(-29);
29

All Magma operators use call-by-value evaluation, like the other intrinsics, except the short-circuit operators `and', `or', and `select', which use call-by-name evaluation. See Expression.

Example

> print 4 ^ 7; // binary operator  ^
16384

> print #[7, 3, 56, 4, 356, 2]; // unary operator # 6

> Plus := '+'; // making an operator into a function > print Plus(4, 4); 8

> print true or "garbage"; // NOT an error true

[Next] [Prev] [Right] [Left] [Up] [Index] [Root]