[erlang-questions] Including function in configuration file

Grzegorz Junka list1@REDACTED
Mon Jul 9 23:03:58 CEST 2018


On 09/07/2018 18: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.
>

If you defined a function in the config how would you verify if it's 
correct? You will need to compile it first. In Erlang you can compile 
any arbitrary file directly in your application, see this for an example:
https://github.com/yoonka/migresia/blob/master/src/migresia_migrations.erl#L193

So, theoretically, you could define a function as a string or binary in 
your config, then in the application write this to a file, compile into 
a binary (i.e. without writing the compiled module to a file) and then 
load directly from that binary and execute. But that sounds a bit weird 
and it's probably not what you need. Maybe you can just tell us what are 
you trying to accomplish?

Best
Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180709/7ebffcbb/attachment.htm>


More information about the erlang-questions mailing list