Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Functional programming 函数为什么接收额外参数_Functional Programming_Elixir - Fatal编程技术网

Functional programming 函数为什么接收额外参数

Functional programming 函数为什么接收额外参数,functional-programming,elixir,Functional Programming,Elixir,当我使用以下代码运行函数时: elements = ["A", "B"] for element <- elements, into: [] do struct(element, []) end elements=[“A”,“B”] 对于元素您看到Kernel.struct/3的原因是Kernel.struct/2内部有一个private子句 错误的原因是没有匹配的function子句,因为第一个参数“A”不是结构或原子。请阅读: struct参数可以是原子(定义defstruct

当我使用以下代码运行函数时:

elements = ["A", "B"]

for element <- elements, into: [] do
  struct(element, [])
end
elements=[“A”,“B”]

对于元素您看到
Kernel.struct/3
的原因是
Kernel.struct/2
内部有一个private子句

错误的原因是没有匹配的function子句,因为第一个参数
“A”
不是结构或原子。请阅读:

struct
参数可以是原子(定义
defstruct
)或
struct
本身


您正在传递的字符串不是有效的参数。

您看到
Kernel.struct/3
的原因是
Kernel.struct/2
内部有一个private子句

错误的原因是没有匹配的function子句,因为第一个参数
“A”
不是结构或原子。请阅读:

struct
参数可以是原子(定义
defstruct
)或
struct
本身


您正在传递一个字符串,该字符串不是有效参数。

您正在运行哪个版本的Elixir?我似乎找不到
struct/3
的定义,只有
struct/2
。您运行的是什么版本的Elixir?我似乎找不到
struct/3
的定义,只有
struct/2
** (FunctionClauseError) no function clause matching in Kernel.struct/3

The following arguments were given to Kernel.struct/3:

    # 1
    "A"

    # 2
    []

    # 3
    #Function<18.114860832/2 in Kernel.struct/2>

Attempted function clauses (showing 4 out of 4):

    defp struct(struct, [], _fun) when is_atom(struct)
    defp struct(struct, fields, fun) when is_atom(struct)
    defp struct(%_{} = struct, [], _fun)
    defp struct(%_{} = struct, fields, fun)