Functions with same name and varying arity using apply

Taylor Venable <>
Thu Jan 20 00:03:56 CET 2011

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

%% test.erl


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]]).

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

More information about the erlang-questions mailing list