Wherever a pattern occurs (let, case, receive, lc, etc.) it can be followed by an optional guard which has the form (when test ...). Guard tests are the same as in vanilla Erlang and can contain the following guard expressions:

  • (quote e)
  • (cons gexpr gexpr)
  • (car gexpr)
  • (cdr gexpr)
  • (list gexpr ...)
  • (tuple gexpr ...)
  • (binary ...)
  • (progn gtest ...) - Sequence of guard tests
  • (if gexpr gexpr gexpr)
  • (type-test e)
  • (guard-bif ...) - Guard BIFs, arithmetic, boolean and comparison operators

An empty guard, (when), always succeeds as there is no test which fails. This simplifies writing macros which handle guards.