Erlang is getting too big

Richard Carlsson richardc@REDACTED
Tue Oct 14 16:41:34 CEST 2003

On Tue, 14 Oct 2003, Thomas Lindgren wrote:

> > But since auto-recognized BIFs override local
> > definitions (sic!),
> > this would probably break a lot of existing code.
> If you mean BIFs that do not need the erlang: prefix,
> then the override nowadays goes in the other
> direction. (And correctly so, IMO.)
> -module(test).
> -compile(export_all).
> abs(X) when X > 0 ->
>    X;
> abs(X) ->
>    -X.
> 1> c(test).
> ... Warning: defining BIF abs/1

Ah, but that warning only tells you that you have defined
a function called abs/1, which is also the name of an
auto-recognized BIF.

And if you call it from the outside, as in "test:abs(-1)",
your function is called, as you expect.

But if you try to use it for a local call, you get into
trouble, because it is overridden by the BIF:

	-export([myabs/1, abs/1]).

	myabs(X) ->

	abs(X) when X > 0 ->
	   {abs, X};
	abs(X) ->
	   {abs, -X}.

1> c(test).
./test.erl:7: Warning: defining BIF abs/1
2> test:abs(1).
3> test:myabs(1).

(And no, the ordering of the functions above does not matter.)

Is this sufficiently confusing?


Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW:
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham

More information about the erlang-questions mailing list