10.5 Records in Guards

Since record expressions are expanded to tuple expressions, creating records and accessing record fields are allowed in guards. However all subexpressions, for example, for field initiations, must be valid guard expressions as well.

Examples:

  1. handle(Msg, State) when Msg==#msg{to=void, no=3} ->
  2. ...
  3.  
  4. handle(Msg, State) when State#state.running==true ->
  5. ...

There is also a type test BIF is_record(Term, RecordTag).

Example:

  1. is_person(P) when is_record(P, person) ->
  2. true;
  3. is_person(_P) ->
  4. false.