我最近开始学习erlang,但遇到了一个让我感到困惑的错误。
最后一行的错误是syntax error before: 'end'
。我看过一些试图找到错误的例子,但我现在完全迷失了。任何想法?
ChannelToJoin = list:keysearch(ChannelName,1,State#server_st.channels),
case ChannelToJoin of
% Channel exists.
{value, Tuple} ->
if
%User is not a member of the channel
not list:member(UserID, Tuple) ->
%Add the user to the channel
Tuple#channel.users = list:append(Tuple#channel.users, [UserID]);
% If the user is already a member of the channel.
true -> true
end;
%Channel doesn't exist
false ->
%Create new channel and add the user to it.
NewState = State#server_st{channels = list:append(State#server_st.channels, NewChannel = #channel{name = ChannelName, users = [UserID]}
end
答案 0 :(得分:5)
倒数第二行NewState = ...
缺少两个右括号:)}
另请注意,您不能在lists:member
内使用if
,因为在保护表达式中不允许函数调用(这是if
允许您使用的)。相反,请使用case
:
case lists:member(UserID, Tuple#channel.users) of
false ->
%% Add the user to the channel
...;
true ->
%% Already a member
ok
end