Functions with same name and varying arity using apply

Taylor Venable taylor@REDACTED
Thu Jan 20 00:03:56 CET 2011


Hi there, is the following possible in Erlang? If I use the following code:

%% test.erl

-module(test).
-export([foo/1,foo/2,bar/2]).

foo(A) -> A.
foo(A, B) -> A + B.

bar(_, []) -> [];
bar(F, [X|Xs]) -> [apply(test, F, X) | bar(F, Xs)].

%% END

2> test:bar(foo, [[1], [2,3]]).
[1,5]

Is there a way to do the same thing without exporting foo/1 and foo/2?
It seems not with apply/3, but maybe some technique with apply/2, or
another way? Thanks for any ideas.

-- 
Taylor C. Venable
http://metasyntax.net/


More information about the erlang-questions mailing list