Erlang compiler error

有些话、适合烂在心里 提交于 2019-12-24 09:21:53

问题


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.


来源:https://stackoverflow.com/questions/3902912/erlang-compiler-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!