I have this case statement:

case {[{atom1,A1},{atom2,A2}],false} of

                {[{A,B},{C,D}], false} -> {A,B}
            end.

There are other cases but i cut them out.

I dont understand why I get the following error:

** exception error: no case clause matching {[{atom1,A1},{atom2,A2}],false} in function expr:myFunct/1 (myModule.erl, line 391)

Why doesn't {[{atom1,A1},{atom2,A2}],false} equal {[{A,B},{C,D}], false}?

有帮助吗?

解决方案

Probably either one of A, B, C, D (or all of them) are already bound to some value when the case clause pattern matches, which is not the same as it should be in order to match.

For this to match the following conditions must be met, at the point where the pattern match happens:

  • A must be unbound, otherwise it must contain the value atom1
  • B must be unbound, otherwise it must contain the same value that A1 does
  • C must be unbound, otherwise it must contain the value atom2
  • D must be unbound, otherwise it must contain the same value that A2 does

其他提示

It's equal. Unless variables A or C already have binded to some value.

It does. The issue can be your surrounding code if at least one of A, B, C or D has already bound value which doesn't match with.

$ erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> A1 = foo, A2 = bar.
bar
2> case {[{atom1,A1},{atom2,A2}],false} of
2> 
2>                 {[{A,B},{C,D}], false} -> {A,B}
2>             end.
{atom1,foo}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top