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:

  1. #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:

  1. #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.


  1. -record(person, {name, phone, address}).
  3. ...
  5. lookup(Name, Tab) ->
  6. ets:match_object(Tab, #person{name=Name, _='_'}).