[erlang-questions] Unique atom with make_ref()?

Adam Kelly cthulahoops@REDACTED
Thu Feb 4 20:11:29 CET 2010


2010/2/4 Daniel Rönnqvist <kdronnqvist@REDACTED>:
> Why sholdn't I use erlang:ref_to_list/1 in application programs? As it
> says here:
>
> http://erlang.org/doc/man/erlang.html#erlang:ref_to_list-1
>
> Let's say that I wanted to create a unique atom, isn't this a good way?
>
> list_to_atom(erlang:ref_to_list(make_ref()))

Start up two nodes.  Run that function on both and they will both
generate the same atom.   It's slightly confusing, but the string
representation of a ref doesn't have the uniqueness property that the
ref does.  If you send the ref itself between nodes, it will appear
differently on each node but be unique on both.  Pids have similar
behaviour.

If you want a unique value that you can store outside of erlang, the
following is pretty good:  {node(), erlang:now()}.  (erlang:now() does
some magic to make sure that it doesn't generate the same value twice
on the same node.)

Adam.


More information about the erlang-questions mailing list