gpt4 book ai didi

Elixir : is_function

转载 作者:行者123 更新时间:2023-12-02 02:48:49 27 4
gpt4 key购买 nike

我想用 is_function 测试一些内置函数,但失败了:

> add = fn a, b -> a + b end
#Function<12.118419387/2 in :erl_eval.expr/5>

> is_function add
true

> is_function is_function # test itself
warning: variable "is_function" does not exist and is being expanded to "is_function()", please use parentheses to remove the ambiguity or change the variable name
iex:27

如何测试内置函数?

最佳答案

您可以使用 Kernel.function_exported?/3 并向其传递模块名称、函数名称和数量来检查:

iex(1)> function_exported?(Kernel, :is_function, 1)
true
iex(2)> function_exported?(Kernel, :is_function, 2)
true
iex(3)> function_exported?(Kernel, :is_function, 3)
false
iex(4)> function_exported?(Kernel, :function_exported?, 3)
true

(Elixir 中无需导入任何模块即可调用的所有函数,例如 is_function+ 均在 Kernel 模块中定义。)

关于 Elixir : is_function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776282/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com