The Erlang VM only allows a limited set of expressions as guards:
-
comparison operators (
==
,!=
,===
,!==
,>
,<
,<=
,>=
); -
boolean operators (
and
,or
) and negation operators (not
,!
); -
arithmetic operators (
+
,-
,*
,/
); -
<>
and++
as long as the left side is a literal; -
the
in
operator; -
all the following type check functions:
- is_atom/1
- is_binary/1
- is_bitstring/1
- is_boolean/1
- is_float/1
- is_function/1
- is_function/2
- is_integer/1
- is_list/1
- is_number/1
- is_pid/1
- is_port/1
- is_record/2
- is_record/3
- is_reference/1
- is_tuple/1
- is_exception/1
-
plus these functions:
- abs(Number)
- bit_size(Bitstring)
- byte_size(Bitstring)
- div(Number, Number)
- elem(Tuple, n)
- float(Term)
- hd(List)
- length(List)
- node()
- node(Pid|Ref|Port)
- rem(Number, Number)
- round(Number)
- self()
- size(Tuple|Bitstring)
- tl(List)
- trunc(Number)
- tuple_size(Tuple)