Patterns
Written as normal data expressions where symbols are variables and use quote to match explicit values. Binaries and tuples have special syntax.
Erlang | LFE |
---|---|
{ok,X} |
(tuple 'ok x) |
error |
'error |
{yes,[X|Xs]} |
(tuple 'yes (cons x xs)) |
<<34,F/float>> |
(binary 34 (f float)) |
[P|Ps]=All |
(= (cons p ps) all) |
Repeated variables are NOT supported in patterns, there is no automatic comparison of values. It must explicitly be done in a guard.
_
as the "don't care" variable is supported. This means that the
symbol _
, which is a perfectly valid symbol, can never be bound
through pattern matching.
Aliases are defined with the (= pattern1 pattern2)
pattern. As in
Erlang patterns they can be used anywhere in a pattern.
CAVEAT: The lint pass of the compiler checks for aliases and if they are possible to match. If not an error is flagged. This is not the best way. Instead there should be a warning and the offending clause removed, but later passes of the compiler can't handle this yet.