clojure中持久数据结构的内存共享(Memory sharing of persistent data structures in clojure)
我已经开始学习Clojure并正在阅读有关结构共享的内容。 我在以下场景中感到困惑:以下定义的序列中的clojure代码在REPL中输入:
1)
(def a [1 2 3])
,
2)(def ba)
,
3)(def a (conj a 4))
,
4)(def b (conj b 5))
,在第4步之后,a和b将共享前三个元素的结构,还是在执行第4步时复制所有值? 如果结构是共享的,那么Clojure如何能够在索引3处返回值?
这有点与Clojure中的结构共享有关,但我仍然感到困惑。 任何形式的帮助将不胜感激。
I have started learning Clojure and was reading about structural sharing. I am confused in the following scenario : following clojure codes are typed in REPL in the sequence defined below :
1)
(def a [1 2 3])
,
2)(def b a)
,
3)(def a (conj a 4))
,
4)(def b (conj b 5))
,After the 4th step, will a and b share the structure for the first three elements or all values will be copied on the execution of 4th step ? If the structure is shared, how will Clojure be able to return us the value at say index 3 ?
This is somewhat related to Structural Sharing in Clojure, but I am still confused. Any kind of help will be appreciated.
原文:https://stackoverflow.com/questions/18762029