kuroda

kuroda

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?

Showing Posts 1 to 10

kip

kip

ex_cldr Core Team

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

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.

patrickdm

patrickdm

Could you suggest some resource to learn about the costs of remote calls please? At this point I’m intrigued and curious! Thank you.

hauleth

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

hauleth

The advantage and disadvantage of the remote calls is exactly the same:

The remote call allows for the hot code reload, which mean that it need to check if there is no newer code each time it is called.

However if you are trying to use local call as a lambda in form of &foo/0 then it will be slower than &__MODULE__.foo/0 as the second can be as a constant so will be faster to call.

NobbZ

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).

hauleth

hauleth

Any remote call need to point to public function.

patrickdm

patrickdm

Thank you very much @hauleth and @NobbZ for the explanation! Is this kind of things (I mean ignorance here) that triggers the impostor syndrome in me.. than I remember It’s all in my mind. Nothing serious indeed. :sweat_smile:

kuroda

kuroda OP

Thank you everyone for answering the question.

Does anyone know where to find a description of a remote function call in the erlang documentation or its source code?

Qqwy

Qqwy

TypeCheck Core Team

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews