Three wishes
Samuel Rivas
samuel@REDACTED
Tue Jul 19 16:25:25 CEST 2005
Richard A. O'Keefe wrote:
> Is there any case in which it is a "must have"?
>
> Why yes, in the common case of things like
>
> if X > Y -> Sign = 1, Abs = X - Y
> ; X < Y -> Sign = -1, Abs = Y - X
> ; X ==Y -> Sign = 0, Abs = 0
> end,
> ... use Sign and Abs ...
>
> where the *point* of the conditional is to bind several variables
> rather than to compute a value.
Well, it is not really a "must" but a "could". 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 ...
I see this more as a potential "best practice" than a reason
for the compiler to print a warning. Having the warnings when an
exported variable is part of another assignment outside the if/match
block seems enough for me.
Best regards.
--
Samuel
More information about the erlang-questions
mailing list