[erlang-questions] clarify: variable as function name
Tue Dec 11 11:34:23 CET 2007
Would it be useful to be able to be able to explicitly create a fun of
an exported function, EXPORT_EXT (113) . It is an clean way of sending
a reference to a exported function.
I do not know ho efficent it is to call compared with an:
apply(Module, Function, [Args1, ... ArgsN]).
Module:Function(Args1, ... ArgsN).
I guess that my previous hack is a no, no.
But I guess it would be simple for the OTP team to add a "real"
make_fun(Module, Function, Arity) function that creates an EXPORT_EXT
(113) to a module i.e. the erlang module.
Then there is no syntax change as it would be for:
F = fun Module:Function/Arity.
2007/12/10, Robert Virding <rvirding@REDACTED>:
> On 10/12/2007, Andreas Hillqvist <andreas.hillqvist@REDACTED> wrote:
> > make_fun(Module, Function, Arity) ->
> > fun Module:Function/Arity.
> You can actually do it today:
> make_fun(M, F, 0) -> fun () -> M:F() end;
> make_fun(M, F, 1) -> fun (A1) -> M:F(A1) end;
> make_fun(M, F, 2) -> fun (A1, A2) -> M:F(A1, A2) end;
> Not beautiful but it works. The only limitation is that you can only reach
> exported functions. Which is as it should be.
More information about the erlang-questions