1. Records
1 Records
1.1 Records and Tuples
The main advantage of using records rather than tuples is that fields in a record are accessed by name, whereas fields in a tuple are accessed by position. To illustrate these differences, suppose that you want to represent a person with the tuple {Name, Address, Phone}
.
To write functions that manipulate this data, remember the following:
- The
Name
field is the first element of the tuple. - The
Address
field is the second element. - The
Phone
field is the third element.
For example, to extract data from a variable P
that contains such a tuple, you can write the following code and then use pattern matching to extract the relevant fields:
Name = element(1, P), Address = element(2, P), ...
Su