我在iex中注意到运行[1] = [ head | tail ]导致编译错误.但是,如果您定义一个函数,例如:
def simple_func([ head | tail ]) do
IO.inspect(head)
IO.inspect(tail)
end
Run Code Online (Sandbox Code Playgroud)
这个论点似乎很匹配.我假设发生了什么事情,我很想知道它是什么.
要匹配的模式位于左侧=,而不是右侧:
iex(1)> [head | tail] = [1]
[1]
iex(2)> head
1
iex(3)> tail
[]
Run Code Online (Sandbox Code Playgroud)