这些运营商在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
答案 0 :(得分:12)
There are some operators that currently have no meaning, but you can use them in macros you define or just define them as functions. For example:
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
The general idea is that Elixir wants to avoid operator proliferation (think libraries that define dozens of new operators) so when defining your macros you need to use the ones that are already there.