这是一个简单的模块,在函数中有 2 个断点,它们正在调用另一个名称与内置函数完全相同的函数:get/1
和put/2
defmodule Test do
def call_put() do
require IEx; IEx.pry
put("k", "v")
end
def call_get() do
require IEx; IEx.pry
get("k")
end
def put(_k, _v)do
IO.puts("Doing put")
end
def get(_k) do
IO.puts("Doing get")
end
end
在shell中执行它:
iex(1)> Test.call_get
Break reached: Test.call_get/0 (lib/test.ex:7)
5: end
6: def call_get() do
7: require IEx; IEx.pry
8: get("k")
9: end
pry(1)> get("a")
:undefined
pry(2)> Test.get("a")
Doing get
:ok
可见,get/1
从调试器调用会导致执行内置get/1
而put/2
不是我Test
模块中的函数。为了正常工作,我需要命名我的函数调用。谁能解释我这种行为?