[erlang-questions] : questions about dict
Raimo Niskanen
raimo+erlang-questions@REDACTED
Tue Aug 21 11:09:26 CEST 2007
On Tue, Aug 21, 2007 at 09:27:49AM +0200, Bjorn Gustavsson wrote:
> Dustin Sallings <dustin@REDACTED> writes:
>
> >
> > >> 2) I can't seem to make a guard for a dict because the record
> > >> format is unavailable to me at compile time (I'm working around this
> > >> by matching tuple and hard-coding a tuple pattern for identifying a
> > >> dict).
> > >
> > > That is intentional (and even mentioned in the documentation).
> > >
> > > There is no portable way to test for a dict in a guard.
> >
> > Where is this documented? I looked around for a while and
> > couldn't find anything either way. There's clearly a gap in my
> > understanding of guards, records, or dicts.
>
> It may be a little subtle, but the documentation for dict says:
>
> "Dict implements a Key - Value dictionary. The representation of a dictionary is not defined."
>
> That means that only the dict module knows about how a dictionary is represented,
> and that you should only use the functions in the dict module to access a dictionary.
>
> If you use knowledge gained from looking at the source of dict to write a guard
> test any, your code could in principle stop to work in a future release of OTP if
> we change the representation.
>
So, you are supposed to maintain that knowledge yourself. You could
e.g wrap all dictionaries in a {dict,UnknownRepresentatio} tuple,
or just know from the context that they are dictionaries.
> /Bjorn
>
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list