Re: Why I cannot use tuple as application env key?

"borja.deregil" <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <[email protected]>
> I want to use tuple as application env key:
> 
> application:set_env(sessions, {backend,Name},  Configuration).
> 
> 
> Why is it forbidden? Why application_controller assumes that I must
> use only atoms?

If you use application:set_env/1 or application:set_env/2, you're right 
that
application_controller will check that your key is an atom.
If you use application:set_env/3, you can use any term as key (I just 
tried locally).

See 
https://github.com/erlang/otp/blob/0f0100618e3d050ea9f00517a4d7ba00bfb740b9/lib/kernel/src/application_controller.erl#L473-L474 
and 
https://github.com/erlang/otp/blob/0f0100618e3d050ea9f00517a4d7ba00bfb740b9/lib/kernel/src/application_controller.erl#L871-L872

> You can try to use persistent option and will see that it doesn't work.

Can you share what doesn't work? I can recommed the approach shared by 
bengt, use
application:get_env/2 at the beggining of your application, and use 
persistent_term or and
ETS table to store configuration in the format that you want. Both ETS 
and persistent_term
allow any Erlang term as the key.

Cheers,
Borja
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.