这些运算符在 Elixir 中是什么意思? ~>>, <<~

What do these operators mean in Elixir? ~>>, <<~

这些运算符在 Elixir 中是什么意思? ~>>, <<~

它们列在这里 http://elixir-lang.org/getting-started/basic-operators.html

我收到以下错误:

iex(28)> b=1
1
iex(29)> b~>>1
** (CompileError) iex:29: undefined function ~>>/2

有些运算符目前没有任何意义,但您可以在您定义的宏中使用它们,或者将它们定义为函数。例如:

defmodule Operators do
  def a ~>> b do
    a + b
  end
end

defmodule Test do
  def test do
    import Operators

    1 ~>> 2
  end
end

IO.inspect(Test.test) # => 3

一般的想法是 Elixir 想要避免运算符激增(想想定义几十个新运算符的库),所以在定义宏时,您需要使用已经存在的宏。