Thrift/Erlang 字符串
我正在尝试在 Erlang 中编写一个简单的 Thrift 服务器,它接受一个字符串并返回一个字符串。
一切似乎都在调用我的函数:
handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
case apply(?MODULE, Function, tuple_to_list(Args)) of
ok -> ok;
Reply -> {reply, Reply}
end.
test([X]) ->
"You sent: " ++ X.
我得到了一个 function_clause。堆栈跟踪显示以下内容:
{function_clause,[{服务器,测试, [<<“w00t”>>]},
{服务器,handle_function,2},...
我的handle_function是从教程文件复制的,所以如果我需要调整它,我不会感到惊讶。有什么想法吗?
I'm trying to write a simple Thrift server in Erlang that takes a string and returns a string.
Everything seems to be working up to the point of calling my function:
handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
case apply(?MODULE, Function, tuple_to_list(Args)) of
ok -> ok;
Reply -> {reply, Reply}
end.
test([X]) ->
"You sent: " ++ X.
I'm getting a function_clause. The stack trace shows the following:
{function_clause, [{server, test,
[<<"w00t">>]},
{server,handle_function, 2}, ...
My handle_function is copied from the tutorial file so I won't be surprised if I need to tweak it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
apply 的最后一个参数应该是“test”的参数列表,例如,如果 tuple_to_list(Args) 导致:
...then:
如果
tuple_to_list(Args)
导致:...then :
所以,如果
{<<"woot">>}
被传递给tuple_to_list
,那就是:...所以:
...但测试的签名要求一个列表作为参数,所以存在不匹配。
That last argument of apply should be a list of arguments to 'test', e.g., if tuple_to_list(Args) resulted in:
...then:
If
tuple_to_list(Args)
resulted in:...then:
So, if
{<<"woot">>}
is being passed totuple_to_list
, that's going to be:...so:
...but test's signature asks for a list as the argument, so there's a mismatch.