[erlang-questions] Where is an ets guide?
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Fri Sep 22 19:52:39 CEST 2006
Jeff Crane wrote:
> Sent: den 22 september 2006 19:12
> To: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] Where is an ets guide?
>
> > > ets:new(mytable,[]).
> > > 16 % that's a tid!
> >
> > Identifiers are supposed to be opaque.. just like the internal
> > representation of dict, etc.
>
> I dont know anything about dict. that doesnt help me
> understand what mytable is for.
>From the ets reference manual
(http://www.erlang.org/doc/doc-5.5/lib/stdlib-1.14/doc/html/ets.html)
"new(Name, Options) -> tid()
Types:
Name = atom()
Options = [Option]
Option = Type | Access | named_table | {keypos,Pos}
Type = set | ordered_set | bag | duplicate_bag
Access = public | protected | private
Pos = int()"
In other words, the first argument is a name.
Among the options is named_table. It is described thus:
"named_table If this option is present, the name Name is associated
with the table identifier. The name can then be used instead of the
table identifier in subsequent operations."
The reference manual doesn't explicitly state that Name per default
_cannot_ be used to address the table. It might perhaps be helpful to
add a paragraph in the introduction explaining the concept of named and
"unnamed" tables.
> > > ets:insert(mytable,{1,"first"}).
> > > % Nope...wtf?
> >
> > mytable isn't the Tid, and you didn't ask for a named table.
>
> What are you talking about? I made a table with a name atom
> of mytable, what is that other than the table name?
If you haven't specified the named_table option, the name serves only as
documentation.
You can create several tables with the same name, as long as at most one
of them has the 'named_table' option.
> > > MyTable2 = ets:new(mytable2,[]).
> > > 19 % that's a tid!
> > >
> > > ets:insert(MyTable2,{2,"second"}).
> > > % true? Um, I'm lost.
> >
> > How lost could you be?
> > > What's the point of the name atom?
> What's the point of the name atom?
> You didn't answer the question, of course I'm lost.
>
> Why is MyTable2 the table reference, when mytable2 should be
> the correct reference? What's the point of
> mytable2 if it's not the named reference? Sheesh.
You can always use the table identifier to address
the table. You can only use the name if you created
the table with the 'named_table' option.
> Again, someone needs to present a decent ets guide.
You may be right. Ets is a pretty important module,
and it has lots of functions that may elude even
fairly experienced erlang programmers.
BR,
Ulf W
More information about the erlang-questions
mailing list