[Next] [Prev] [_____] [Left] [Up] [Index] [Root]
Mutation assignment

Mutation assignment

A mutation assignment is an easy and efficient way of making a simple change to an identifier that already exists. Its syntax is

> IDENTIFIER o:= EXPRESSION;

Magma evaluates the expression, then applies the operator to the identifier and the result, and finally assigns the end result to the identifier.

The mutation assignment is equivalent to

> IDENTIFIER := IDENTIFIER o EXPRESSION;

in its overall effect. However, the mutation version may be faster because of optimization; Magma can compile it more efficiently.

Example

> x := 47;
> x +:= 5;
> print x;
52

> y := 93; > y div:= 7; > print y; 13

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