Hi there,

I've now seen singly linked lists used as a way of describing Clojure's 
immutable data structures with the claim that they're used to implement lists.

The example usually goes as follows. A has the list '(1 2 3) which is 
implemented as follows:

 A
 |
 |
 V
+---+      +---+      +---+
| 1 | ---> | 2 | ---> | 3 |
+---+      +---+      +---+

B then wishes to add 0 to the front and achieves this by simply adding to the 
head of A's list:


 B           A  
 |           |
 |           |
 V           V
+---+      +---+      +---+      +---+
| 0 | ---> | 1 | ---> | 2 | ---> | 3 |
+---+      +---+      +---+      +---+

B therefore shares data with A, both have their separate immutable lists and 
everything is good with the world. Importantly, the performance characteristics 
of the underlying data structure are honoured (which wouldn't be the case with 
a naive copying strategy).

Now, the question I have is what happens if C wants to add 4 to the end of B's 
list? Does this imply that C has to copy all of B's list in order to add a new 
element? Clearly C can't just share data and add it to B's list as it would 
break immutability guarantees.

Sam

---
http://sam.aaron.name

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to