我有一个Erlang模块,它导出两个同名但arity不同的方法:proc/1和proc/2中的一个或多个。当使用MFA形式的方法时,如何指定应该使用/2还是/1?请参见示例:
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
mbyulnm01#
The number of elements in your list of arguments specifies if you are using /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
Here I am using apply/3 and using the Module:Function:Args format to first call reverse/1 and then reverse/2 .
apply/3
Module:Function:Args
reverse/1
reverse/2
1条答案
按热度按时间mbyulnm01#
The number of elements in your list of arguments specifies if you are using
/1
or/2
:Here I am using
apply/3
and using theModule:Function:Args
format to first callreverse/1
and thenreverse/2
.