[erlang-questions] dict:from_list/1 fragility
Matej Kosik
kosik@REDACTED
Mon Dec 17 22:11:28 CET 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Friends,
I think there are two problems with the
dict:from_list/1
function.
First: it is not trottel-fest (robust against my stupitidity). It lets me call it as follows:
E = dict:from_list([{a,b},{c,d}]).
Instead of any kind of complain, it vigorously continues and binds E to an invalid dictionary. At
the first sight, things seem to be fine. This
dict:fetch(a, E).
yields
b
and this
dict:fetch(c, E).
yields
d
Hitherto everything seems fine. However, after I update the dictionary:
F = dict:update(e, f, E).
and try to retrieve newly added element
dict:fetch(e, F).
I get
[f]
I have used dictionaries to store PIDs of processes, the dictionary is at the boot-time constructed
via dict:from_list/1 constructor and later it I call dict:append/3 function to get the richer
dictionary. However, this led to the situation that some values had
pid()
"type" and others were of
[pid()]
"type".
Do not you think that that the
dict:from_list
should fail immediatelly if one calls it as I called it:
dict:from_list([{a,b},{c,d}])
It should succeed only if the values are lists, such as
dict:from_list([{a,[b]}, {c, [d]}])
- ----------------------------------------------------------------------------
Second: do not you think that the documentation should mention this fact?
I admit that I may be thinking in wrong (non-Erlang way) but this is how it seems to me.
- --
Matej Kosik
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHZuYAL+CaXfJI/hgRArxNAJ9oZZ+wt9P1oJW4Gdqm+9B3zMSv9ACffqkP
J/aOAH/IzdX7FwxtQps6/TA=
=zzkM
-----END PGP SIGNATURE-----
More information about the erlang-questions
mailing list