小编use*_*439的帖子

之前的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 = …
Run Code Online (Sandbox Code Playgroud)

erlang

0
推荐指数
1
解决办法
1596
查看次数

Erlang,与列表foreach匹配

我一直在Erlang为一个学校项目做一个聊天应用程序,但我遇到了一个问题.我正在尝试使我的程序并发,为了这样做,我为每个通道发送的消息启动一个新线程.我这样做是使用列表:foreach,但我想确保我不会向输入频道的人发送消息.

request(State, {message, {UserID,UserPID}, Token}) ->
case catch lists:member({UserID,UserPID}, State#channel.users) of
    false ->
        {{error, user_not_joined}, State};
    true -> 
        spawn( fun() ->
        ListOfUsers = State#channel.users,
        UserPIDs = lists:map(fun ({_, V}) -> V end, ListOfUsers),
        %spawn( fun() ->end)
        lists:foreach( 
            fun(UserPID) -> ok end,
            fun(PID) ->
                spawn( fun() -> genserver:request(PID, {message_from_server, State#channel.name, UserID, Token}) end) 
            end, UserPIDs) end),
        {ok, State}
end;
Run Code Online (Sandbox Code Playgroud)

我非常想做的是匹配foreach中的UserPID.截至目前,我只收到警告:

channel.erl:39:警告:变量'UserPID'未使用channel.erl:39:警告:变量'UserPID'在'fun'中被遮蔽

第3行很有趣(UserPID) - > ok结束,

干杯

erlang

0
推荐指数
1
解决办法
392
查看次数

标签 统计

erlang ×2