知道传递函数的参数个数(erlang)

AJe*_*Jed 6 erlang

在ERLANG:假设我们有一个函数f(),它将F1作为输入,其中F1是一个函数.有没有办法知道F1的输入参数的数量.

我觉得有一个解决方案,但我不确定.例如:

 -module(high).
 -compile(export_all).

 f1() -> 1.
 f2(X) -> X. 
 f3(X, Y) -> {X,Y}. 

 run(F) -> io:format("F ~p ~n", [F]).
Run Code Online (Sandbox Code Playgroud)

那么,有没有办法让函数run/1知道有关传递函数的信息[主要是传递函数的输入参数的数量].

注意:请注意,这是一个理论问题.注意:应用程序的代码(有趣的,[参数])在开源中可用..这可能是我猜的.

Odo*_*rus 13

二郎神:fun_info(娱乐,元数).

例如

F = fun(A,B) -> A+B end.
#Fun<erl_eval.12.111823515>
3> erlang:fun_info(F,arity).
{arity,2}
Run Code Online (Sandbox Code Playgroud)