A long time ago we were used to have ListDict and, as expected, using a
list as a dictionary is a very bad idea as it performs very poorly. So the
reason keywords only allow atoms is to put emphasis on their use cases of
being a very specific data structure for passing options and not a general
purpose one.

So if you are trying to use it as a key-value store and arrived to the
conclusion you cannot, it is doing its job. :)

PS: I believe OptionsParser does not leak atoms as we check those
accordingly. If it does, please open up a bug report.




*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Sun, Jan 8, 2017 at 8:08 PM, Wiebe-Marten Wijnja <
[email protected]> wrote:

> I recently worked on some code where I wanted to store {key, value}-pairs
> and newer values entered for the same key should shadow older values.
> So, I tried using Keyword lists.
> However, the keys in my list were not atoms but Strings -- they contain
> properties that users might enter, and therefore it is unsafe to work with
> atoms directly (as they are never garbage collected, at some point they can
> and will make your system run out of memory).
>
> But then this turned out not to work! Keyword requires keys to always be
> an atom <http://elixir-lang.org/docs/stable/elixir/Keyword.html#content>.
>
> This choice has been made deliberately in the past (the documentation
> clearly states it, using the access protocol for keywords will throw a
> descriptive error message, etc.),
> but it is unclear why.
>
>
> Above use case seems relatively general to me.
>
> For instance, OptionsParser.parse/1 always returns a Keyword list with
> atoms right now, and suffers from the atom-garbage-problem because of it.
> (OptionsParser.parse/2 allows you to specify what switches should be
> allowed, but this is not appropriate for all use cases)
>
>
> Why is the current behaviour as it is right now?
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/69fe6eeb-19a1-4edf-8908-
> ddfe70734b60%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/69fe6eeb-19a1-4edf-8908-ddfe70734b60%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LBeUoWqKQdwev6CW4wR53ONbtLE3QeOakTE0Ti7vMQsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to