45 Records

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 between rec( and ), and separating them by commas ,. Each component consists of the name, the assignment operator :=, and the value. The empty record, i.e., the record with no components, is written as rec().

    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).

Subsections

  1. Accessing Record Elements
  2. Record Assignment
  3. Identical Records
  4. Comparisons of Records
  5. Operations for Records
  6. In for Records
  7. Printing of Records
  8. IsRec
  9. IsBound
  10. Unbind
  11. Copy
  12. ShallowCopy
  13. RecFields
Previous Up Next
Index

GAP 3.4.4
April 1997