Erlang/OTP R10B-10 has been released

Romain Lenglet <>
Wed Mar 22 05:52:48 CET 2006

> 	Another thing. A major use of the preprocessor is conditional
> 	compilation, e.g.
> 	  pi() -> 3.0.
> 	  -else.
> 	  pi() -> 3.14159.
> 	  -endif.

Doesn't that look like a need for polymorphism / abstract 

There are several ways to do that in Erlang:

- at clause-level (as suggested earlier):

start(Alternative) -> pi:pi(Alternative).

- module(pi).
pi(us) -> 3.0;
pi(_) -> 3.14159.

- at module-level:

start(Module) -> Module:pi().

pi() -> 3.0.

pi() -> 3.14159.

- at process level (I think, the most "Erlang-ish"):

start(Pid) -> gen_server:call(Pid, pi).

handle_call(pi, From, State) ->
    {reply, 3.0, State}.

handle_call(pi, From, State) ->
    {reply, 3.14159, State}.

I just wanted to illustrate that the problem of choosing 
alternatives in an architecture can be solved by polymorphism / 
abstract delegation and depencency injection. Separating 
alternatives in different modules / processes and using an ADL 
solves such configuration problems.
No need for a pre-processor, or for a -D<feature>=<value> 
compiler option.
I admit that for the simple example above it is like using a 
hammer to kill a fly. ;-)
And they may not solve problems such as compiler / dialect 
differences as Richard A. O'Keefe described. But do such 
problems ever occur in Erlang?


More information about the erlang-questions mailing list