2.12 Assignments

var := expr;

The assignment has the effect of assigning the value of the expressions expr to the variable var.

The variable var may be an ordinary variable (see Variables), a list element selection list-var[int-expr] (see List Assignment) or a Record Assignment). Since a list element or a record component may itself be a list or a record the left hand side of an assignment may be arbitrarily complex.

Note that variables do not have a type. Thus any value may be assigned to any variable. For example a variable with an integer value may be assigned a permutation or a list or anything else.

If the expression expr is a function call then this function must return a value. If the function does not return a value an error is signalled and you enter a break loop (see Break Loops). As usual you can leave the break loop with quit;. If you enter return return-expr; the value of the expression return-expr is assigned to the variable, and execution continues after the assignment.

    gap> S6 := rec( size := 720 );; S6;
    rec(
      size := 720 )
    gap> S6.generators := [ (1,2), (1,2,3,4,5) ];; S6;
    rec(
      size := 720,
      generators := [ (1,2), (1,2,3,4,5) ] )
    gap> S6.generators[2] := (1,2,3,4,5,6);; S6;
    rec(
      size := 720,
      generators := [ (1,2), (1,2,3,4,5,6) ] ) 

Previous Up Top Next
Index

GAP 3.4.4
April 1997