kuroda
What is the definition of a remote function?
When we try to evaluate an Elixir code m = %{}; m.foo = 1 on IEx, it emits the following error message :
** (CompileError) iex:1: cannot invoke remote function m.foo/0 inside a match
I know that we cannot call m.foo/0 inside a pattern match, but I have some questions:
- What is a remote function exactly?
- What is called a function that is not a remote function?
I cannot find a definition of this word within the documentation.
Perhaps, it refers to a remote call, which is used in the left . right?
Most Liked
kip
A remote function is a function in a module that isn’t this one.
A local function is one defined in the current module.
There is a slight cost in the BEAM to execute a remote function over a local one, but not material to a design decision.
NobbZ
A remote call is every function call which is qualified by its module.
defmodule M do
def f(0), do: 0
def f(n) when n > 0, do: M.f(n-1) + 2
end
The recursive call here is a remote call, with all of its costs.
hauleth
That is not fully true as __MODULE__.foo() is also remote call. In short the difference between remote and local call is that you put the module name before remote call.
hauleth
Any remote call need to point to public function.
NobbZ
Though here we have to remember, that for &__MODULE__.foo/0 to work, the function needs to be exposed/public, by using def, while when doing &foo/0 the function is allowed to be private (defp).







