The Erlang digraphs module surprised me by mutating state.
When dealing with other data structure modules in Erlang, for instance the sets module, the instance of the data structure passed in, is unmodified. The function returns a new, altered version e.g.
>S = sets:new().
>sets:size(S).
0
>T = sets:add_element(S, "element").
>sets:size(S).
0
>sets:size(T).
1
This is not the behaviour when dealing with the digraph module.
>G = digraph:new().
>digraph:no_vertices(G).
0
>digraph:add_vertex(G, "vertex").
>digraph:no_vertices(G).
1
Firstly, why is the digraph library different in this respect?
Secondly, and more importantly, how is the digraph module adding new state against an existing binding?
I assume the state is being stored in another process which the digraph module is identifying using the existing and unaltered binding G. Is this the case? Or are there other ways of modifying state associated with a binding?