Records are next to lists the most important way to collect objects together. A record is a collection of components. Each component has a unique name, which is an identifier that distinguishes this component, and a value, which is an object of arbitrary type. We often abbreviate value of a component to element. We also say that a record contains its elements. You can access and change the elements of a record using its name.
Record literals are written by writing down the components in order
), and separating them by commas
component consists of the name, the assignment operator
:=, and the
value. The empty record, i.e., the record with no components, is
gap> rec( a := 1, b := "2" ); # a record with two components rec( a := 1, b := "2" ) gap> rec( a := 1, b := rec( c := 2 ) ); # record may contain records rec( a := 1, b := rec( c := 2 ) )
Records usually contain elements of various types, i.e., they are usually not homogeneous like lists.
The first section in this chapter tells you how you can access the elements of a record (see Accessing Record Elements).
The next sections tell you how you can change the elements of a record (see Record Assignment and Identical Records).
The next sections describe the operations that are available for records In for Records, and Printing of Records).
The next section describes the function that tests if an object is a record (see IsRec).
The next sections describe the functions that test whether a record has a component with a given name, and delete such a component (see IsBound and Unbind). Those functions are also applicable to lists (see chapter Lists).
The final sections describe the functions that create a copy of a record (see Copy and ShallowCopy). Again those functions are also applicable to lists (see chapter Lists).