【发布时间】:2017-09-09 11:54:18
【问题描述】:
在“Programming Elixir”一书中,Dave Thomas 展示了一个示例
handle_open = fn
{:ok, file} -> "Read data: #{IO.read(file, :line)}"
{_, error} -> "Error: #{:file.format_error(error)}"
end
handle_open.(File.open("code/intro/hello.exs"))
handle_open.(File.open("nonexistent"))
我不明白为什么第二次调用函数会进入第二次流程。 还有为什么我们不将参数传递给 func:
handle_open = fn(file)
?
【问题讨论】: