[erlang-questions] conditional expressions

Michael McDaniel erlangy@REDACTED
Sat Nov 15 19:40:53 CET 2008


On Sun, Nov 16, 2008 at 05:17:52AM +1100, damien morton wrote:
>    1> case [] of [] -> X = aaa; X -> ok end.
> 
>    aaa
> 
>    2> case bbb of [] -> X = aaa; X -> ok end.
> 
>    ** exception error: no case clause matching bbb
> 
>    am I missing something?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 From section '6.8 Case' of the Erlang Reference Manual (Version 5.6.5)

"If there is no matching pattern with a true guard sequence, a case_clause run-time error will occur."

 bbb does not match anything in the second case above; you could substitute
 aaa for X in the second case and it would result the same.

3> X.
aaa


~Michael


> 
>    On Sun, Nov 16, 2008 at 4:42 AM, mats cronqvist <[1]masse@REDACTED>
>    wrote:
> 
>       strangely, this also works;
>      case foo() of
>       [] -> X = bar();
>       X -> ok
>      end
>       as long as X is bound in each clause, you're golden.
>       this might qualify as a gotcha.
>       mats
> 
> References
> 
>    1. mailto:masse@REDACTED

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us




More information about the erlang-questions mailing list