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

Mikael Pettersson mikpe@REDACTED
Fri Jun 11 20:31:25 CEST 2010

Richard O'Keefe writes:
 > On Jun 10, 2010, at 1:40 AM, Raimo Niskanen wrote:
 > > I might argue that since it is a call to an exported function it  
 > > must be to
 > > some *other* function, not the local with the same name.
 > Why?  Suppose we have a module
 > 	-module(foo).
 > 	-export([bar/1]).
 > 	bar(N) when N > 0 -> ?MODULE:bar(N-1);
 > 	bar(0) -> 'DONG!'.
 > In what sense is the call to ?MODULE:bar/1 a call to some *other*
 > function than the bar/1 here before us?

Because in Erlang a call with both module and function names
supplied is a "remote" call, which always invokes the latest
version of the module whose name was given.  So if a process P
is executing code in version 1 of the module, a newer version
2 of the module is loaded, and P calls ?MODULE:F(...), then
that call invokes F in version 2 of the module, not version 1.

More information about the erlang-questions mailing list