Pattern Matching Again
To round off this chapter, we’ll go back to pattern matching one more time.
The following table has some examples of patterns and terms; all the variables in the patterns are assumed unbound. A term is just an Erlang data structure. The third column of the table, marked Result, shows whether the pattern matched the term and, if so, the variable bindings that were created. Read through the examples, and make sure you really understand them.
Pattern |
| Term | Result |
|
|
| Succeeds
with |
|
|
| Succeeds
with |
|
|
| Fails—the tuples have different shapes |
|
|
| Succeeds with |
|
|
| Succeeds with |
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access