[erlang-questions] Where is an ets guide?

Sean Hinde sean.hinde@REDACTED
Fri Sep 22 20:00:33 CEST 2006


On 22 Sep 2006, at 18:12, Jeff Crane wrote:

>>> 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.

That is the point - you don't need to know.

>
>>> 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?

Actually you didn't. In order to get a globally named table you have  
to provide the option named_table. This is described under that  
option in the documentation.

>
>>> 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.

The point of the name atom is also a bit unclear to me I have to say.  
It is a bit useless unless the named table option is also given. It  
appears in some debug printouts somewhere.

MyTable2 is the reference because of what the documentation for  
ets:new/2 says in the first line:

"Creates a new table and returns a table identifier which can be used  
in subsequent operations"

To get much further in your erlang studies you must understand the  
difference between a variable and an atom (Hint: Variables start with  
upper case letters).  Your line of code has assigned the return value  
from the ets:new/2 function to the Variable MyTable2. MyTable2 holds  
the reference.

>
>> It helps to read *all* of the docs for a function.
>> There's a
>> named_table option, which lets you specify the Tid
>> as an atom:
>>
>> * 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 docs are pretty sufficient, if you read them.
>>
>> -bob
>
> I have read them. They aren't sufficient, when you're
> not already vetted in erlang. It's too bad you are
> unable to see it.
>
> Again, someone needs to present a decent ets guide.

The ets manual is actually very good. What it is not is a beginners  
guide to Erlang. It assumes you have some basic understanding of the  
language - it is a reference after all.

Might I suggest a little more study of the language is in order at  
this point.

Sean







More information about the erlang-questions mailing list