elixir - 当计算机别名具有连字符时尝试连接节点时出现 "(ArithmeticError) bad argument in arithmetic expression"

标签 elixir

我正在学习一个教程,并且应该将节点连接在一起。我使用以下命令启动了总共四个终端窗口:

iex --sname one (two, three etc)

然后我运行

 Node.connect(:two@DAL-SW-JH-LT)
** (ArithmeticError) bad argument in arithmetic expression: :two@DAL - SW
    :erlang.-(:two@DAL, SW)

最佳答案

错误提示:

** (ArithmeticError) bad argument in arithmetic expression: :two@DAL - SW
:erlang.-(:two@DAL, SW)

也就是说,尝试在那里调用减法运算符。我们唯一可疑的减法运算符是 -,它粘合节点名称的部分内容。

节点名称用原子表示。根据文档,Atom ...

...starts with a colon (:) which must be immediately followed by an underscore or a Unicode letter. The atom may continue using a sequence of Unicode letters, numbers, underscores, and @. Atoms may end in ! or ?. [...]

If the colon is immediately followed by a pair of double- or single-quotes surrounding the atom name, the atom is considered quoted. In contrast with an unquoted atom, this one can be made of any Unicode character (not only letters), such as :'🌢 Elixir', :"++olá++", and :"123".

也就是说,解决方案是引用原子,有效地用引号包围它

Node.connect(:"two@DAL-SW-JH-LT")

无论节点名称是否不包含破折号,都不需要引号。

关于elixir - 当计算机别名具有连字符时尝试连接节点时出现 "(ArithmeticError) bad argument in arithmetic expression",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59571543/

相关文章:

Elixir 更新嵌套关键字列表

elixir - 如何使用 Ecto 获得明天的日期时间?

elixir - 生成N个自然数的序列

default-parameters - 具有多个子句的命名函数的 Elixir 默认参数

elixir - 埃克托+ Elixir : How do I query a hashmap field?

匹配 1 次或 2 次出现的正则表达式

elixir - Ecto迁移中如何动态更新字段值?

elixir - 使用字符串查询仓库

elixir - 设置 unique_constraint Ecto

elixir - 如何测试函数保护子句中结构的值?