Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang persistent data structures

Tags:

erlang

clojure

As I've understood, when you create a new list with expression like the following, Erlang doesn't copy L1, it just copies H.

L2 = [H|L1]

Does Erlang have persistent a data structure (see Persistent data structure) for dict, that is, when you add/remove/modify nodes in the tree only few elements are being copied (like in Clojure)?

like image 990
adolgarev Avatar asked Nov 05 '10 09:11

adolgarev


1 Answers

You have misunderstood the situation when you build a list using [H|T]. It is as you say that T is not copied but neither is H. All that happens is that a new list cell is prepended to T with a reference to H as its head (its tail is T). When working with lists the only bits which are created are the actual list cells and never the data in each cell.

The same happens when working with dict. When you modify (add/delete elements) in the dict only the actual dict structure is modified and not the actual data in the dict. Also it is smart so as to only copy as little of the dict structure as is necessary to make the modification.

So, yes, Erlang has persistent data structures. In that respect clojure is like Erlang (we were around long before it).

like image 126
rvirding Avatar answered Oct 09 '22 10:10

rvirding