[Next] [Prev] [Right] [____] [Up] [Index] [Root]
Assignment

Assignment

The Magma assignment statement has the basic form

> IDENTIFIER := EXPRESSION;

Notice that the assignment symbol := consists of two keyboard characters, and that like all statements, an assignment statement must end with a semicolon ( ; ).

Magma evaluates the expression and assigns it to the identifier. For example, after this statement:

> x3 := 6 + 9;

the identifier x3 has the value 15. You can see it by typing

> print x3;
15

If the identifier already had a value then that value is destroyed.

No information about the expression used for the value is stored in the identifier. For instance,

> s := 6;
> t := s + 7;
> s := 0;
> print t;
13

The identifier t has not been changed by the change to s, although s was used to calculate t.

Some functions return more than one value. To find out how to assign these values to identifiers, see Multiple Assignment.

Simple modifications of an identifier can be made with the mutation assignment. See Mutation assignment.

Example

> fred := 45 * 3;
> y := fred^2 - 2;

Mutation assignment: > print fred; 135 > fred +:= 15; > print fred; 150

Subscreens
[Next] [Prev] [Right] [____] [Up] [Index] [Root]