Next: , Previous: Assert, Up: Statements


6.11.2 The Assignment

To set the value of an already defined variable to a different value, use a statement of the following form:

     $var := expr;

The expression expr is evaluated and the result is assigned to the variable $var. The variable must have already been defined.

You can assign the elements of a list value to multiple variables at once:

     <$var1, $var2, ... > := expr;

The first, second, ... element of expr, which must be a list, is assigned to variable $var1, $var2, ... respectively. Any of these variables may be followed by a path. The number of variables must match the length of the list value.

You can optionally specify a path behind the variable that is to be set by an assignment:

     $var.part1.part2 := value;

In this case, only the value of $var.part1.part2 will be set to value; the remainder of the variable $var will be unchanged. Each part must be an expression that evaluates to a symbol, a number or a list of symbols and numbers.

You can also use one of four other assignment operators instead of the operator `:=': The statement $var :=+ value; is a shorthand for $var := $var + value;. The same holds for the assignment operators `:=-', `:=*', and `:=/'. Here, $var may be followed by a path again.