[erlang-questions] Re: No, really, please stop misinterpreting what I wrote

James Hague james.hague@REDACTED
Thu Sep 17 17:43:58 CEST 2009


Wow, this discussion has blown up :)

Originally, what I wanted was a way to manually make sure that terms
are shared. This is easy to do by having a data structure function
that works like this:

  {New_Tree, Item_in_Tree} = some_tree:insert(Tree, Item)

None of the library functions have this, as far as I can tell. I pass
in a some data item, like a string, and it gets searched for in a tree
(or similar data structure). If it exists, the same tree and a pointer
to the item already in the tree are passed back. I can use the
returned item rather than the original, knowing that sharing is
occurring if it's possible. If the item doesn't exist, then I get back
the new tree and exactly the same item I passed in.

The reason I brought up Erlang semantics here, is that so that the
check for if something is shared or not could be handled at the
runtime level.

A tangential topic is about enforcing sharing across all data
structures--with hash consing, for example--but that's a major change
that doesn't make sense.

Then there's the issue of terms with shared data blowing up when
converted to a binary and back, or sent to another process.  This is a
potentially critical flaw in some cases, but it's more easily dealt
with than the previous paragraph. And it's not what I was originally
talking about :)


More information about the erlang-questions mailing list