Tutorial: LFE Records

3 Querying Records

Below is a brief explanation of the workings of the generated functions associated with any given record definition.

(make-person name '"Robert" age 54)

Will create a new person record with the name field set to "Robert", the age field set to 54 and the address field set to the default "".

(match-person name name age 55)

Will match a person with age 55 and bind the variable name to the name field of the record. Can use any variable name here.

(is-person john)

Test if john is a person record.

(emp-person age '$1)

Create an Ets Match Pattern for record person where the age field is set to $1 and all other fields are set to '_.

(person-address john)

Return the address field of the person record john.

(person-address)

Return the index of the address field of a person record.

(set-person-address john '"back street")

Sets the address field of the person record john to "back street".

(set-person john age 35 address '"front street")

In the person record john set the age field to 35 and the address field to "front street".