[erlang-questions] Overriding built-in functions in a module
Richard O'Keefe
ok@REDACTED
Tue Jun 15 03:12:04 CEST 2010
On Jun 12, 2010, at 6:31 AM, Mikael Pettersson wrote:
> Richard O'Keefe writes:
>> 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.
No, the fact that a call is a remote call does NOT make it a
call to a function OTHER THAN THE FUNCTION IT CALLS.
In this example, the function that is called is foo:bar/1.
> 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.
As the Spartans once put it, "if".
If the module is *NOT* reloaded, which is, let's face it,
*almost all the time*, then there is no intelligible criterion
by which it could be called "some *other* function".
Even if the module is reloaded, that is not SOME OTHER FUNCTION.
It is still foo:bar/1.
When you talk about a newer version of module 'foo',
you call it a newer version, not ANOTHER module.
But when you talk about a newer version of foo:bar/1,
suddenly it's an *other* function.
Let's be consistent in the way we talk about things.
More information about the erlang-questions
mailing list