admin管理员组

文章数量:1291260

Here, José Valim explicitly wrote that it isn't persistent.

But the official documentation here (5th para.) says otherwise, it seems.

I'm confused because I don't know how to check it myself yet. Can anyone help me, please?

Here, José Valim explicitly wrote that it isn't persistent.

But the official documentation here (5th para.) says otherwise, it seems.

I'm confused because I don't know how to check it myself yet. Can anyone help me, please?

Share Improve this question asked Feb 13 at 15:04 al.hramal.hram 13 bronze badges 2
  • This question is similar to: Does Elixir have persistent data structures similar to Clojure?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. – Starship Commented Feb 13 at 15:31
  • I can not find the word "persistent" anywhere in the linked official documentation. – Peaceful James Commented Feb 15 at 13:15
Add a comment  | 

1 Answer 1

Reset to default 0

Elixir tuples and Clojure vectors are both immutable and persistent as defined here:

a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure.

The key difference is efficiency. Any update operation for Elixir tuples such as put_elem need to copy the whole tuple, meaning they cannot be achieved efficiently and will always be linear. This would disqualify it in practice for most algorithms that would need to run successive updates to build a result.

On the other hand, Clojure vectors, Erlang's :array or Aja vectors (disclosure: I'm the author) provide efficient update operations that leverage structural sharing and only need to copy the structure partially, typically in logarithmic cost. This series of articles explains the concept well.

本文标签: Stillis tuple now a persistent data structure in Elixir or notStack Overflow