elixir - Elixir 中的斜线符号是什么意思?

标签 elixir

在 Elixir 文档中,他们一直使用带有斜线的奇怪符号,例如:

is_boolean/1
IO.puts/1
String.length/1
is_function/2
++/2

我只是猜测,但我认为它指的是arity。但如果是这样的话,为什么文档中的任何地方都没有提到魔鬼呢?这似乎不是 IT 中的任何一种标准惯例(至少,在我从事 IT 工作的 20 多年中,我从未见过这样的惯例)。

最佳答案

来自 page 2, Basic types入门文档:

Note: Functions in Elixir are identified by name and by number of arguments (i.e. arity). Therefore, is_boolean/1 identifies a function named is_boolean that takes 1 argument. is_boolean/2 identifies a different (nonexistent) function with the same name but different arity.



Erlang/Elixir Syntax: A Crash Course 中也有描述。 :

Here we create a module named hello_module. In it we define three functions, the first two are made available for other modules to call via the export directive at the top. It contains a list of functions, each of which is written in the format <function name>/<arity>. Arity stands for the number of arguments.



我可能会推测这往往被归为 Elixir 文献中的旁注,因为它直接来自 Erlang。尽管使用 Elixir 不需要 Erlang 知识,但当人们记录从 Erlang 派生的 Elixir 软件时,这种遗漏是一个常见的错误。

关于elixir - Elixir 中的斜线符号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36778114/

相关文章:

elixir - 这个 Ecto Constraint Error 试图告诉我什么?

authentication - 如何在phoenix中实现用户认证

elixir - 无法在 Phoenix/Elixir 中渲染没有布局的错误 View

curl - Elixir HTTPoison 握手失败

functional-programming - 为什么 Elixir 不使用多方法/协议(protocol)?

exception-handling - Elixir:正确的打印方式__STACKTRACE__

soap - 带有客户端 ssl 证书的 Elixir SOAP (detergentex)

elixir - 升级 Elixir 后出现 "Phoenix.HTML.Engine.init/1 is undefined or private"和 "Plug.Conn.__struct__/1 is undefined"等错误

postgresql - 如何使用 PostgreSQL 在 Ecto 中使用点列类型

http - Phoenix 测试不接受大写的响应 header