Search code examples
erl

Erlang : variable '_' is unbound


I'm trying to use "_" in Case but I'm missing some thing. What i'm doing is :

case (Packet =:= #xmlel{name = <<"message">>, attrs = [_, {<<"type">>,<<"chat">>}], children = _}) of
    true ->
        ?INFO_MSG("True ###### Packet ~p", [Packet]);
    _ ->
        ?INFO_MSG("False ###### Packet ~p", [Packet])
end,

And the error is : variable '_' is unbound.

I want this variable "_" to mean in this function every thing.

Like -->

attrs = [Whatever, {<<"type">>,<<"chat">>}]

children = Whatever

How can I do it? thnx.


Solution

  • The problem is:

    You cannot use '_' on the right of '='

    You can only put it on the left of the '='

    e.g.

    {_,4} = {x,y} (correct)

    {x,y} = {_,4} (wrong)