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)?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With