Erlang compiler error

2019-08-09 18:25发布

问题:

I have the following code

loop(Data) ->
receive
    {Key, Value} ->
    [{Key, Value}|Data];
    {Key} ->
        member(Key, Data);
14  loop(Data);
    stop ->
        io:format("server_stopped"),
        ok  
end .

and I get the following error (I put the line number 14 in the code)

./dist_erlang.erl:14: syntax error before: ';' ./dist_erlang.erl:2: function loop/1 undefined ./dist_erlang.erl:28: Warning: function member/2 is unused

I am not sure what the syntax problem is with the above code. I have a method called member which is giving the error because of a different syntax error on line 14 I am sure.

Any help is appreciated thanks.

回答1:

In Erlang, expressions are separated by commas (and clauses are separated by semicolons). Try:

loop(Data) -> 
    receive 
        {Key, Value} -> 
            loop([{Key, Value}|Data]); 
        {Key} -> 
            member(Key, Data),
            loop(Data);
        stop -> 
            io:format("server_stopped"), 
            ok   
    end.


标签: erlang