I am reading "Programming Elixir 1.3" (PragPub) and ran across something that doesn't make much sense to me. On page 42 the author describes closures pointing out that in
greeter = fn name -> (fn -> "Hello #{name}" end) end the returned function 'remembers' the value of the provided name parameter. This is the nature of closures. However, 2 pages later he gives the following example:
defmodule Greeter do def for(name, greeting) do fn (^name) -> "#{greeting} #{name}" (_) -> "I don't know you" end end end I don't understand why the name identifier is pinned in the first function head since it should have the value passed in 'remembered' as part of the closure.