With regards to [p1 = %Product{}, p2 = %Product{}]
- the pattern match is essentially
[%Product{}, %Product{}] = Catalog.list_productsi.e. a two element list where each element has to be aProductstructure - otherwise the match will fail. - after the match is successful the names
p1andp2are bound to their values.p1is bound to the first element in the list andp2is bound to the second element in the list.
Now consider [p1, p2] = Catalog.list_products:
- the pattern match is essentially
[_, _] = Catalog.list_productsi.e. a two element list where each element can be any data type - otherwise the match will fail. - after the match is successful the names
p1andp2are bound to their values.p1is bound to the first element in the list andp2is bound to the second element in the list.
Finally [^p1, ^p2] = Catalog.list_products
- The match will only succeed if the first element of the list matches the current content of
p1and the second element matches the current content ofp2(and the list has exactly two elements).






















