2014-02-19 32 views
0

我最近開始學習erlang,但遇到了一個讓我不解的錯誤。Erlang之前的語法錯誤:'end'

錯誤是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

你能發表更多的代碼嗎?除了你試圖更新'if'中的'Tuple'記錄外,這對我來說看起來很好。請記住:erlang中的變量是隻讀的 – ZeissS

回答

5

的倒數第二行,NewState = ...,在缺席兩場右括號:)}

另外請注意,您不能使用lists:memberif,函數調用不保護表達式允許入內(這是什麼if讓你使用)。相反,使用case

case lists:member(UserID, Tuple#channel.users) of 
    false -> 
     %% Add the user to the channel 
     ...; 
    true -> 
     %% Already a member 
     ok 
end 
+0

乾杯,這真的很有幫助! – user2270439