> < ^ Date: Mon, 28 Mar 1994 16:41:00 +0100
> < ^ From: Goetz Pfeiffer <Goetz.Pfeiffer@NUIGalway.ie >
> < ^ Subject: Re: FiniteField limitations and [-operator
The Gap Students wrote in their letter of 28-Mar-94:
>
> Secondly we would like to know if the "[" operator could be redefined for
> records, like "+", "-" and "^". It would be very useful if we could use
> commands like:
>
> word := Code[4];      # Where "Code" is a record containing a code.
>                       # "word" would become the fourth codeword
>
> We hope you can help.

Record fields in GAP can be accessed via the '.' operator. This operator
takes as his right operand the name of a record field. The name of the
field can also be a parenthesized string, e.g,

obj.("operations");

is a valid way to ask for the record field 'operations' of a record 'obj'.
So it is possible to work with variable record filed names.

Moreover, record field names can be numbers. A group 'g' with 4
generators, for instance, often has the record components 1 to 4 which
contain the generators. So it is possible to get the second generator
by the simple construction 'g.2'.

The final point: if the name of the record field is a (small) integer
then this integer can used as parenthesized recor field name - without
transforming it into a string.

So, if in you example, 'Code' is a record, containing the code words
in the fields 1 to n, say, the it is for example possible to have
constructions like the following,

for i in [1..n] do
   Print(Code.(i), "\n");
od;

which will print each word of the code on a single line.

Goetz Pfeiffer.


> < [top]