Trrift / Erlang String

I am trying to write a simple Thrift server in Erlang that takes a string and returns a string.

Everything seems to work until the moment my function is called:

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 get function_clause. The stack trace shows the following:

{function_clause, [{server, test, [& L; <"w00t" β†’]},
{server, handle_function, 2}, ...

My handle_function is copied from the training file, so I won’t be surprised if I need to fine-tune it. Any ideas?

+4
source share
1 answer

This last apply argument should be the argument list for 'test', for example, if tuple_to_list (Args) resulted in:

 [1] 

... then:

 test(1) 

If tuple_to_list(Args) resulted in:

 [1,2] 

... then:

 test(1,2) 

So, if {<<"woot">>} is passed to tuple_to_list , it will be:

 [<<"woot">>] 

... So:

 test(<<"woot">>) 

... but the test signature requests the list as an argument, so there is a mismatch.

+6
source

All Articles