[erlang-questions] Invoking a function based on name only
Fri Sep 14 15:57:50 CEST 2007
igwan <igwan@REDACTED> writes:
> 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
> 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"
That was correct in R10B and in some R11B releases.
We will update that part of the Efficiency Guide in R12B.
The compiler was changed in one of the R11B releases to
internally rewrite apply(M, Foo, [A1,A2,An]) to M:Foo(A1, A2, An);
thus, exactly the same code is produced and you can choose the
version you find more readable (personally, I find M:Foo(A1, A2, An)
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions