Erlang:函数调用返回的构造的情况?
代码生成的错误如下所示:Erlang:函数调用返回的构造的情况?,erlang,switch-statement,message-passing,Erlang,Switch Statement,Message Passing,代码生成的错误如下所示: 2> X = "2". "2" 3> case_:main(X). main 50 sender 50 ** exception error: bad argument in function case_:sender/1 (case_.erl, line 14) in call from case_:main/1 (case_.erl, line 6) 4> Z = 2. 2 5> case_:main(Z). ** ex
2> X = "2".
"2"
3> case_:main(X).
main 50
sender 50
** exception error: bad argument
in function case_:sender/1 (case_.erl, line 14)
in call from case_:main/1 (case_.erl, line 6)
4> Z = 2.
2
5> case_:main(Z).
** exception error: bad argument
in function io:format/3
called as io:format(<0.25.0>,"main ~p~n",2)
in call from case_:main/1 (case_.erl, line 5)
6>
幸运的是,badarg修复很容易完成。将术语列表作为第二个参数。见:
(Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> io:format("main ~p~n", 2).
** exception error: bad argument
in function io:format/3
called as io:format(<0.24.0>,"main ~p~n",2)
2> io:format("main ~p~n", [2]).
main 2
ok
然后,repl中的交互:
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> c("case_").
{ok,case_}
2> case_:main(2).
main 2
sender 2
receiver
Received 4
ok
幸运的是,badarg修复很容易完成。将术语列表作为第二个参数。见:
(Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> io:format("main ~p~n", 2).
** exception error: bad argument
in function io:format/3
called as io:format(<0.24.0>,"main ~p~n",2)
2> io:format("main ~p~n", [2]).
main 2
ok
然后,repl中的交互:
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> c("case_").
{ok,case_}
2> case_:main(2).
main 2
sender 2
receiver
Received 4
ok