---
title: "Access and Modification Functions"
canonical: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Records/access-modification.html"
source: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Records/access-modification.md"
part: "Sets, Sequences, and Mappings"
chapter: "Records"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Sets, Sequences, and Mappings", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/index-sets-sequences-mappings.md"}
  - {"title": "Records", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Records/index-records.md"}
prev: {"title": "Creating a Record", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Records/creation-record.md"}
next: {"title": "Mappings", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Mappings/index-mappings.md"}
intrinsics:
  - {"name": "Format", "signature": "Format(r): Rec -> RecFormat"}
  - {"name": "Names", "signature": "Names(F): RecFrmt -> [ MonStgElt ]"}
  - {"name": "Names", "signature": "Names(r): Rec -> [ MonStgElt ]"}
  - {"name": "r`fieldname", "signature": "r`fieldname: Rec, Fieldname -> Elt"}
  - {"name": "`", "signature": "r`fieldname := expression;"}
  - {"name": "delete", "signature": "delete r`fieldname: Rec, Fieldname -> Nil"}
  - {"name": "assigned", "signature": "assigned r`fieldname: Rec, Fieldname -> BoolElt"}
  - {"name": "r`` s", "signature": "r`` s: Rec, String -> Elt"}
examples:
  - "ex-81cb41"
---

# Access and Modification Functions

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

<a id="function-format-rec"></a>
## `Format(r): Rec -> RecFormat`

The format of record $r$.

<a id="function-names-recfrmt"></a>
## `Names(F): RecFrmt -> [ MonStgElt ]`

The fieldnames of the record format $F$ returned as a sequence of strings.

<a id="function-names-rec"></a>
## `Names(r): Rec -> [ MonStgElt ]`

The fieldnames of record $r$ returned as a sequence of strings.

<a id="literal-literal-r-fieldname-rec-fieldname-elt"></a>
## ``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$.

<a id="literal-literal-r-fieldname-expression"></a>
## ``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.

<a id="operation-operation-delete-rec-fieldname-nil"></a>
## ``delete r`fieldname: Rec, Fieldname -> Nil``

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

<a id="operation-operation-assigned-rec-fieldname-boolelt"></a>
## ``assigned r`fieldname: Rec, Fieldname -> BoolElt``

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

<a id="literal-literal-r-s-rec-string-elt"></a>
## ```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 $\verb|r`fieldname|$ may be used, including in left hand side assignment, `assigned` and `delete`.

<a id="example-ex-81cb41"></a>
## `Example: Accessing Record Fields (ex-81cb41)`

```magma
> 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 | >
```
