Elixir中的斜杠表示什么意思? [英] What does the slash notation in Elixir mean?

查看:100
本文介绍了Elixir中的斜杠表示什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Elixir文档中,他们继续使用带有斜杠的奇数表示法,例如:

In the Elixir docs, they keep using an odd notation with slash, for example:

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

我只是在猜测,但我认为它指的是友善。但是如果是这样,为什么在文档的任何地方都没有提到魔鬼?并不是说这是IT中的任何一种标准惯例(至少,这不是我20多年来在IT中见过的惯例)。

I'm just guessing, but I think it refers to arity. But if that's the case, why the devil isn't it mentioned anywhere in the docs? It's not as if this is any kind of standard convention in IT (at least, not one that I've ever seen in my 20+ years in IT).

推荐答案

第2页,基本类型 入门文档中的a>:


注:Elixir中的功能按名称和编号标识论点(即arity)。因此, is_boolean / 1 标识一个名为 is_boolean 的函数,该函数带有1个参数。 is_boolean / 2 标识具有相同名称但具有不同Arity的另一个(不存在)函数。

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语法:速成班


在这里,我们创建一个名为 hello_module 的模块。在其中,我们定义了三个函数,前两个可通过顶部的 export 指令供其他模块调用。它包含一个函数列表,每个函数都以< function name> /< arity> 的格式编写。 Arity代表参数的数量。

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知识,但是当人们记录源自Elixir的软件来自Erlang时,这种遗漏是一个常见错误。

I might speculate that this tends to be relegated to a side note in Elixir literature because it comes straight from Erlang. Although Erlang knowledge shouldn't be necessary to use Elixir, such omissions are a common mistake when people document software that is derived as Elixir is from Erlang.

这篇关于Elixir中的斜杠表示什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆