27.1 Accessing Record Elements

  • rec.name O

    The above construct evaluates to the value of the record component with the name name in the record rec. Note that the name is not evaluated, i.e. it is taken literal.

    gap> r := rec( a := 1, b := 2 );;
    gap> r.a;
    1
    gap> r.b;
    2
    

  • rec.(name) O

    This construct is similar to the above construct. The difference is that the second operand name is evaluated. It must evaluate to a string or an integer otherwise an error is signalled. The construct then evaluates to the element of the record rec whose name is, as a string, equal to name.

    gap> old := rec( a := 1, b := 2 );;
    gap> new := rec();
    rec(
       )
    gap> for i in RecNames( old ) do
    >  new.(i) := old.(i);
    > od;
    gap> new;
    rec(
      a := 1,
      b := 2 ) 
    

    [Top] [Up] [Next] [Index]

    GAP 4 manual
    February 2000