[erlang-questions] questions about dict

Bjorn Gustavsson bjorn@REDACTED
Tue Aug 21 09:27:49 CEST 2007


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.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list