之前的Erlang语法错误:'结束'

use*_*439 0 erlang

我最近开始学习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
Run Code Online (Sandbox Code Playgroud)

leg*_*cia 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
Run Code Online (Sandbox Code Playgroud)