我正在学习一个教程,并且应该将节点连接在一起。我使用以下命令启动了总共四个终端窗口:
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)
也就是说,elixir尝试在那里调用减法运算符。我们唯一可疑的减法运算符是 -
,它粘合节点名称的部分内容。
节点名称用原子表示。根据文档,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/