문제

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