[erlang-questions] Including function in configuration file

Roger Lipscombe <>
Mon Jul 9 21:15:44 CEST 2018


No. The '#Fun<stuff>' isn't really a thing; it's just how the function
is printed in the shell.

If you want to reference a function in a config file, it needs to be a
real function, and you need to reference it by name. If you don't know
which module it's implemented in, you'll need to specify that in your
config file as well. Something like this:

[
  {my_app,
    [
      {my_magic_func, {the_module, func_name}}
    ]}
].

Then, in your code that reads the configuration value, you need to
explicitly invoke the function with erlang:apply...

    {ok, {Module, Func}} = application:get_env(my_app, my_magic_func),
    erlang:apply(Module, Func, [Arg1, Arg2]) % calls
the_module:func_name(Arg1, Arg2)



On 9 July 2018 at 19:57, Code Wiget <> wrote:
> Hi,
>
> Say I want to include a function as an environment variable
>
> I can do this:
>  application:set_env(App, Key, NewValue).
>
> Is there any way to do this from a .config file? Such as:
>  [{my_app, [ {my_fun, #Fun<my_app.12.39472874>}]}]
>
> — this gives a compile error.
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>


More information about the erlang-questions mailing list