gpt4 book ai didi

erlang - Erlang 的导出语法/x 是什么意思?为什么是斜线,然后是数字?

转载 作者:行者123 更新时间:2023-12-04 10:19:33 25 4
gpt4 key购买 nike

-export([consult/1,
dump/2,
first/1,
for/3,
is_prefix/2).

我正在阅读文档并与上面的语法混淆。 /1是什么意思, /2 , /3在上面的列表中?

最佳答案

/1, /2, /3等被称为"Arity"函数的 Arity 表示该函数接受的参数数量。

在 Erlang 中,两个同名但元数不同的函数是两个不同的函数,因此每个函数都是显式导出的。引用 Erlang documentation是说:

A function is uniquely defined by the module name, function name, and arity.



例如,如果您有两个函数:
do_something() -> does_something().

do_something(SomeArg) -> some_something_else(SomeArg).

在你的模块顶部,你只有
-export([do_something/0]).

然后只会导出带有零参数的 do_something(即,可以从系统中的其他模块访问)。

关于erlang - Erlang 的导出语法/x 是什么意思?为什么是斜线,然后是数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13597522/

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