Erlang:循环列表 - badarg

时间:2015-08-03 01:43:43

标签: list erlang

我的问题是在我使用列表的函数中:任何函数都无法完成查看给定列表。以下是我得到的错误:

{badarg,
[{genserver,request,3,
     [{file,
          [99,58,47,85,115,101,114,115,47,68,97,118,105,100,47,
           68,101,115,107,116,111,112,47,71,106,111,114,100,32,
           102,114,195,131,194,165,110,32,103,114,117,110,100,
           101,110,47,103,101,110,115,101,114,118,101,114,46,101,
           114,108]},
      {line,33}]},
 {lists,any,2,[{file,"lists.erl"},{line,1223}]},
 {server,loop,2,
     [{file,
          [99,58,47,85,115,101,114,115,47,68,97,118,105,100,47,
           68,101,115,107,116,111,112,47,71,106,111,114,100,32,
           102,114,195,131,194,165,110,32,103,114,117,110,100,
           101,110,47,115,101,114,118,101,114,46,101,114,108]},
      {line,27}]},
 {genserver,loop,2,
     [{file,
          [99,58,47,85,115,101,114,115,47,68,97,118,105,100,47,
           68,101,115,107,116,111,112,47,71,106,111,114,100,32,
           102,114,195,131,194,165,110,32,103,114,117,110,100,
           101,110,47,103,101,110,115,101,114,118,101,114,46,101,
           114,108]},
      {line,13}]}]}}

我使用以下代码填充列表:

channels = channels ++ [{Channel}]

频道是字符串,频道初始化为 [] 。最后,#27导致错误:

#24 loop(St, {Nick, PID, disconnect}) ->
#25     case lists:keymember(Nick, 1, St#server_st.users) of
#26         false   -> {{error, user_not_connected, "Nick doesn't exist on server."}, St};      
#27         true -> case lists:any(fun(F) -> genserver:request(F, {Nick, PID, is_member}) end, St#server_st.channels) of
#28             true -> {{error, leave_channels_first, "Still in a channel."}, St};
#29             false -> {ok, St#server_st{users = lists:delete({Nick, PID}, St#server_st.users)}}
#30         end
#31     end;

其中 F 用作PID。我怎么会发现它是如何填充列表的问题,但不管我如何扭曲和转动它我最终得到相同的结果。

1 个答案:

答案 0 :(得分:2)

错误来自 genserver:request / 2 调用,检查传递的参数是否对函数定义有效。例如,根据上面的信息,第27行中的F将是包含字符串而不是PID的元组。