10.2 Creating Records
The following expression creates a new Name record where the value of each field FieldI is the value of evaluating the corresponding expression ExprI:
- #Name{Field1=Expr1,...,FieldK=ExprK}
The fields can be in any order, not necessarily the same order as in the record definition, and fields can be omitted. Omitted fields get their respective default value instead.
If several fields are to be assigned the same value, the following construction can be used:
- #Name{Field1=Expr1,...,FieldK=ExprK, _=ExprL}
Omitted fields then get the value of evaluating ExprL instead of their default values. This feature is primarily intended to be used to create patterns for ETS and Mnesia match functions.
Example:
- -record(person, {name, phone, address}).
- ...
- lookup(Name, Tab) ->
- ets:match_object(Tab, #person{name=Name, _='_'}).