Three wishes
Thomas Lindgren
thomasl_erlang@REDACTED
Tue Jul 19 17:35:37 CEST 2005
--- Samuel Rivas <samuel@REDACTED> wrote:
> Personally, I feel
> matching the if result is more erlangish (arguing
> whether it is better
> or worse is more a matter of taste);
>
> test(X, Y) ->
> {Sign, Abs} = if X > Y -> {1, X - Y};
> X < Y -> {-1, Y - X};
> X == Y -> {0, 0}
> end,
> ... More sentences ...
But doing it the other way REALLY IS, historically
speaking, the Erlang way. :-)
test(X,Y) ->
if X > Y -> Sign = 1, Abs = X-Y;
X < Y -> Sign = -1, Abs = Y-X;
true -> Sign = 0, Abs = 0
end,
%% use Sign, Abs
(Though due to the warnings you get nowadays, I tend
to pass around tuples.)
Happily, the compiler nowadays gets rid of most
intermediate tuples. In the days when it didn't, using
them reduced performance, of course.
Best,
Thomas
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the erlang-questions
mailing list