[erlang-questions] Invoking a function based on name only

Bob Ippolito bob@REDACTED
Fri Sep 14 01:10:55 CEST 2007


On 9/13/07, Kevin A. Smith <kevin@REDACTED> wrote:
> If I have the name of the function and the module it belongs to, how
> can I invoke it? I tried cobbling together erl_scan and friends but
> the embedded macros in the code gave me some heartburn. Any pointers?
>

It's really not clear to me what you're trying to do, but you can get
the list of exported functions and their arity from M:module_info().

1> proplists:get_value(exports, lists:module_info()).
[{append,2},
 {append,1},
 {subtract,2},
 {nth,2},
 {nthtail,2},
 {prefix,2},
 ...]

And you can call them with the apply/3 BIF.

2> apply(lists, append, ["foo", "bar"]).
"foobar"

-bob



More information about the erlang-questions mailing list