[erlang-questions] Convert atom and arity into fun

Jeroen Koops koops.j@REDACTED
Fri Sep 5 12:35:48 CEST 2008


Thanks, just what I was looking for.

On Fri, Sep 5, 2008 at 12:31 PM, Gleb Peregud <gleber.p@REDACTED> wrote:
> On Fri, Sep 5, 2008 at 12:22 PM, Jeroen Koops <koops.j@REDACTED> 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
>> erlang-questions@REDACTED
>> 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