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

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

They are listed here http://elixir-lang.org/getting-started/basic-operators.html

I get the following error:

 iex(28)> b=1 1 iex(29)> b~>>1 ** (CompileError) iex:29: undefined function ~>>/2 
+7
source share
1 answer

There are some operators that currently have no meaning, but you can use them in the macros that you define, or simply 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 propagation (think of libraries that define dozens of new operators), so you need to use existing ones to define your macros.

+12
source

All Articles