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

igwan igwan@REDACTED
Fri Sep 14 07:24:17 CEST 2007


It is worth noting that if the number of arguments is known at compile 
time, it's more efficient to use Module:Function(Arg1, Arg2, ...) than 
apply/3.
 From the the Efficiency Guide : "The syntax |M:Foo(A1,A2,An)| (also 
referred to as implicit apply, where M and Foo are bound variables) 
where equivalent with |apply(M,Foo,[A1,A2,An])| in releases pre 
OTP-R10B. The compiler will now optimize this syntax giving it better 
performance than apply/3"

igwan

Dustin Sallings a écrit :
> On Sep 13, 2007, at 15:42 , Kevin A. Smith 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?
>>     
>
> 1> apply(list_to_atom("erlang"), list_to_atom("now"), []).
> {1189,724492,627140}
>
>   




More information about the erlang-questions mailing list