Access and Modification Functions

Fields of records may be inspected, assigned, and deleted at any time.

Format(r): Rec -> RecFormat

The format of record \(r\).

Names(F): RecFrmt -> [ MonStgElt ]

The fieldnames of the record format \(F\) returned as a sequence of strings.

Names(r): Rec -> [ MonStgElt ]

The fieldnames of record \(r\) returned as a sequence of strings.

r`fieldname: Rec, Fieldname -> Elt

Return the field of record \(r\) with this fieldname. The format of \(r\) must include this fieldname, and the field must be assigned in \(r\).

r`fieldname := expression;

Reassign the given field of \(r\) to be the value of the expression. The format of \(r\) must include this fieldname, and the expression’s value must satisfy (directly or by coercion) any restriction on the field.

delete r`fieldname: Rec, Fieldname -> Nil

(Statement.) Delete the current value of the given field of record \(r\).

assigned r`fieldname: Rec, Fieldname -> BoolElt

Returns true if and only if the given field of record \(r\) currently contains a value.

r`` s: Rec, String -> Elt

Given an expression \(s\) that evaluates to a string, return the field of record \(r\) with the fieldname corresponding to this string. The format of \(r\) must include this fieldname, and the field must be assigned in \(r\). This syntax may be used anywhere that r`fieldname may be used, including in left hand side assignment, assigned and delete.

Example: Accessing Record Fields (ex-81cb41)

Run in calculator (opens in a new tab)

> RF := recformat< n : Integers(), misc, seq : SeqEnum >;
> r := rec< RF | >;
> s := rec< RF | misc := "adsifaj", n := 42, seq := [ GF(13) | 4, 8, 1 ]>;
> t := rec< RF | seq := [ 4.7, 1.9 ], n := 51/3 >;
> u := rec< RF | misc := RModule(PolynomialRing(Integers(7)), 4) >;
> V4 := u`misc;
> assigned r`seq;
false
> r`seq := Append(t`seq, t`n); assigned r`seq;
true
> r;
rec<RF | seq := [ 4.7, 1.9, 17 ]>
> // The following produces an error:
> t``(s`misc);

>> t``(s`misc);
          ^
Runtime error in `: Field 'adsifaj' does not exist in this record
> delete u``("m" cat "isc"); u;
rec<RF | >

Run in calculator (opens in a new tab)