[erlang-questions] Special syntax for dictionaries
Jayson Vantuyl
kagato@REDACTED
Fri May 7 22:33:00 CEST 2010
Recently, I submitted a patch to make term_to_binary have a "safe" option (i.e. doesn't create new atoms). It was accepted. My use case was decoding binaries from the network and dropping them into a pattern-match to make simple network protocols. It turned out that I had no problem just creating the atoms I needed and letting the conversion fail if I got a bad atom.
Perhaps you could do something similar in the JSON or YAML decoder? Just use list_to_existing_atom/1. If it fails, collect that key into a 'unknown keys' dictionary or just throw it away if you don't need to save / use the extra data.
It would be perhaps a little ugly, but it should work. I've always found that a little judicious design can generally prevent atom leakage.
Good luck!
--
Jayson Vantuyl
On May 7, 2010, at 1:16 PM, Sergey Samokhin <prikrutil@REDACTED> wrote:
>> I personally don't think that we need or should have a special syntax
>> for dicts
>
> After some thinking and rereading I should admit that Richard O'Keefe
> is right and what I actually need is more like frames/structs than
> dictionaries (actually, I don't even need indexes on keys, because my
> documents are quite small). Garbage collected atoms + frames/structs
> are enough.
>
> With atoms not being garbage collected frames/stuct can only be
> *almost* dynamic, because using them for representing deep and dynamic
> data structures (JSON/XML/YAML) will soon lead to leaking atoms.
>
> --
> Sergey Samokhin
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
More information about the erlang-questions
mailing list