【发布时间】:2017-09-08 12:27:19
【问题描述】:
这是一个简单的模块,在函数中有 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 模块中的函数。
为了正常工作,我需要命名我的函数调用。谁能解释一下这种行为?
【问题讨论】:
-
我认为当前模块的功能不会在
IEx.pry会话中自动“导入”。您可以在会话开始时执行import Test。
标签: debugging erlang elixir beam