> ## 3 Pattern Matching

> ### 3.1 Pattern Matching

> Variables are bound to values through the pattern matching mechanism. Pattern matching occurs when evaluating a function call, `case`- and `receive`- expressions and match operator (=) expressions.

> In a pattern matching, a lefthand side pattern is matched against a righthand side term. If the matching succeeds, any unbound variables in the pattern become bound. If the matching fails, a run-time error occurs.

> Examples:

>     1> X.
>     ** 1: variable 'X' is unbound **
>     2> X = 2.
>     2
>     3> X + 1.
>     3
>     4> {X, Y} = {1, 2}.
>     ** exited: {{badmatch,{1,2}},...} **
>     5> {X, Y} = {2, 3}.
>     {2,3}
>     6> Y.
>     3

Copyright © 1991-2003 Ericsson Utvecklings AB