我有一个Erlang
模块,它导出两个名称相同但数量不同的方法:proc/1
和proc/2
.
使用 形式的方法时MFA
,如何指定/2
应该使用 或/1
?参见例如:
spawn(?MODULE,proc,[22]) % how to tell i want the `/1` arity method
spawn(?MODULE,proc,[11,22]) % `/2`arity method
我有一个Erlang
模块,它导出两个名称相同但数量不同的方法:proc/1
和proc/2
.
使用 形式的方法时MFA
,如何指定/2
应该使用 或/1
?参见例如:
spawn(?MODULE,proc,[22]) % how to tell i want the `/1` arity method
spawn(?MODULE,proc,[11,22]) % `/2`arity method
参数列表中的元素数量指定您是否使用/1
or /2
:
1> apply(lists, reverse, [[a, b, c]]).
[c,b,a]
2> apply(lists, reverse, [[a, b, c], [tail1, tail2]]).
[c,b,a,tail1,tail2]
3> length([[a, b, c]]).
1
4> length([[a, b, c], [tail1, tail2]]).
2
在这里,我使用apply/3
并使用Module:Function:Args
格式先调用reverse/1
然后reverse/2
.