[erlang-questions] Convert atom and arity into fun

Gleb Peregud <>
Fri Sep 5 12:31:18 CEST 2008


On Fri, Sep 5, 2008 at 12:22 PM, Jeroen Koops <> wrote:
> Hi,
>
> The answer to this question is probably obvious, but I can't find it
> after searching around for a while:
>
> Given a function's name as an atom and an arity (for instance as
> returned by module_info(exports)), how can I convert this into a fun
> that I can invoke?
>
> Thanks in advance,
>
> Jeroen Koops
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

Check out erlang:apply/3 (it's a BIF). It is described in manual (man erlang).

You can use Module:Function(Arg1, Arg2, ...) where Module and Function
are variables bound to appropriate atoms. Like this:

Module = lists,
Function = flatlength,
[1, 2] = Module:Function([1], [2])


-- 
Gleb Peregud
http://gleber.pl/

Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong



More information about the erlang-questions mailing list