[erlang-questions] conditional expressions

Robert Virding <>
Sat Nov 15 22:42:46 CET 2008


You are evaluating these in the shell. In the first case X is bound to aaa,
which means that when you evaluate the second case X is already bound. Which
means that there is no matching clause. If you do:

1> case [] of [] -> X = aaa; X -> ok end.
aaa
2> case bbb of [] -> Y = aaa; Y -> ok end.
ok
3> {X,Y}.
{aaa,bbb}

it works.

Robert

2008/11/15 damien morton <>

> 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?
>
> On Sun, Nov 16, 2008 at 4:42 AM, mats cronqvist <> 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
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081115/b33480ab/attachment.html>


More information about the erlang-questions mailing list