[erlang-questions] Overriding built-in functions in a module

Igor Ribeiro Sucupira <>
Fri Jun 4 05:39:19 CEST 2010

On Thu, Jun 3, 2010 at 10:00 PM, Richard O'Keefe <> wrote:
> So let's do what the first error message says:
> *    4  bar() -> ?MODULE:spawn(fun (X) -> X+1 end).
> m% erlc foo.erl
> ./foo.erl:6: Warning: defining BIF spawn/1
> ./foo.erl:6: Warning: function spawn/1 is unused
> There's an explicit call there, how can it not be used?

This was a little bit unrelated to the topic. Given that you can't
call a non-exported function with that syntax, that code is certainly
not calling the local fun spawn/1, since it's not exported.
Considering it's not called anywhere in the module, it's then unused.
That's another characteristic of Erlang you're questioning (the reason
why you can't call a non-exported LOCAL function with module syntax).

As for the other characteristic (local functions not overriding
built-ins in local calls), I totally agree with you and share your
worries. I have Erlang code in production and would be happy if
upgrades to newer version of Erlang would require as few changes as

Best regards.

> Change it again, so that now it reads
> *    1  -module(foo).
>     2  -export([bar/0,spawn/1]).
>     3
> *    4  bar() -> ?MODULE:spawn(fun (X) -> X+1 end).
>     5
>     6  spawn(F) -> F(41).
> Erlc is now silent, and foo:bar() gives the expected answer.
> The price is that a function which was never meant to be exported
> (and because of the clash with a built in function never _should_
> be exported, to avoid confusion) *has* to be exported, and a call
> to a purely local function has to be a remote call.
> This is silly.

More information about the erlang-questions mailing list