[erlang-questions] is there "return" in Erlang.

Kostis Sagonas kostis@REDACTED
Mon Feb 28 19:01:53 CET 2011


Edmond Begumisa wrote:
> How about...
> 
> -define(CONF1, ..).
> -define(CONF2, ..).
> 
> judge() ->
>    judge({a, get_a()}).
> 
> judge({a, ?CONF1}) ->
>    do_something(?CONF1);
> judge({a, _}) ->
>    judge({b, get_b()});
> judge({b, ?CONF2}) ->
>    do_other_thing(?CONF2);
> judge({b, _}) ->
>    do_things().

Now, why on earth would you ever want to do that?  Wrap two terms in a 
tuple only to take them apart by pattern matching?

What's wrong with using an auxiliary judge function with two separate 
arguments instead?

Or even better why not use separate judge_a and judge_b functions that 
are both more efficient and make the programmer's intention clearer?

Sorry for the authoritative tone, but please think a bit more before you 
give "advice" to novices; they might actually take your advice literally 
and think that this is the proper way of writing programs in Erlang.

Kostis


More information about the erlang-questions mailing list