small medium large xlarge

20 Nov 2017, 05:21
Marco Carvalho (10 posts)

I’m trying to wrap my head around this statement on page 38:

“We pass 2 and 3 as arguments, and Elixir tries to match these arguments to the parameters a and b, which it does by giving a the value 2 and b the value 3. It’s the same as when we write”

{a, b} =  {1, 2}

references the following function defined on page 37:

iex>​ sum = ​fn​ (a, b) -> a + b ​end​
#Function<12.17052888 in :erl_eval.expr/5>
iex>​ sum.(1, 2)

I don’t see how {a. b} = {1, 2} if we pass 2 and 3 as arguments to the sum anonymous function. Is this a typo? Or, am I missing a fundamental concept with pattern matching?

Please advise

11 Nov 2017, 21:55
Dave Thomas (396 posts)

Looking at what I wrote, I agree it was probably wrong to use different values in the tuple-based assignment. I was trying to differentiate it from the function call, but I can see where that would cause confusion.


Dave Thomas

20 Nov 2017, 05:19
Marco Carvalho (10 posts)

No problem, Dave! Thanks for your continued community support.

You must be logged in to comment