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

  • IsRecord( obj ) C
  • IsRecordCollection( obj ) C
  • IsRecordCollColl( obj ) C

    gap> IsRecord( rec( a := 1, b := 2 ) );
    true
    gap> IsRecord( IsRecord );
    false
    

  • RecNames( rec ) A

    returns a list of strings corresponding to the names of the record components of the record rec.

    gap> r := rec( a := 1, b := 2 );;
    gap> RecNames( r );
    [ "a", "b" ] 
    

    Note that you cannot use the string result in the ordinary way to access or change a record component. You must use the rec.(name) construct (see Accessing Record Elements and Record Assignment).

    Sections

    1. Accessing Record Elements
    2. Record Assignment
    3. Identical Records
    4. Comparisons of Records
    5. IsBound and Unbind for Records
    6. Record Access Operations

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000