[erlang-questions] Erlang elseif

Christian chsu79@REDACTED
Fri Nov 21 10:37:54 CET 2008


> You can implement
>
>   If <expression1> == true then <result1>
>   elseif <expression2> then <result2>
>   else <result3>
>
> in erlang as follows
>
> if <expresson1> == true ->
>     <result1>;
>    <expression2> ->
>     <result2>;
>    true ->
>     <result3>
> end.

A very important limitation in erlang's "if" expression is that the
tests needs to be guards. If it is okay to execute all tests, every
time, then one can of course do

E1 = <expression1>,
E2 = <expression2>,
if
   E1 -> <result1>;
   E2 -> <result2>;
   true -> <result3>
end


I've had a feeling that there is an if-else chain expression called
"cond" just waiting to happen?

cond
  Test1 ->
      Result1;
  Test2 ->
      Result2;
  Test... ->
      Result...;
   true ->
      yay
end

The cond would in be identical to

case Test1 of
   true -> Result1;
   false ->
      case Test2 of
         true -> Result2;
         false ->
            case Test... of
               true -> Result...
               false -> yay
            end
      end
end

I dont know where I got this impression that "cond" was waiting to
happen. Is it not? Does it need an EEP? Are there objections to it?
Does it need a reference implementation?



More information about the erlang-questions mailing list