Something that simple really scratch my head: cannot invoke remote function :erlang.+/2 inside a match

I run this :

iex(3)> 1 + 2 = 3
** (CompileError) iex:3: cannot invoke remote function :erlang.+/2 inside a match

but it works on https://repl.it/languages/elixir

Erlang/OTP 20.0
 iex
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [kernel-poll:false]

Interactive Elixir (1.3.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
nil
iex(2)> 
nil
iex(3)> 1 + 2 = 3
3
iex(4)> 

Anybody any idea about this?

At runtime, the left side of the = operator is matched to the
right side. The left side is called a pattern, whereas on the right side you have an expression that evaluates to an Elixir term

From the book: Elixir in Action.

So, if you reverse it

3 = 1 + 2

it will work

I’m not entirely sure what that online site is doing, but I get an error if I actually run this in a Repl:

ben:canopy ben$ iex
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Interactive Elixir (1.10.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1 + 2 = 3
** (CompileError) iex:1: cannot invoke remote function :erlang.+/2 inside a match

Can we put function call in pattern on left side?

You cannot no.

2 Likes