Confusion regarding common references in original tree and it's copy returned by COPY-TREE [duplicate]

StackOverflow https://stackoverflow.com/questions/22105197

Question

Chapter 13. Beyond Lists: Other Uses for Cons Cells of Practical Common Lisp states that objects referenced in common by the copy of the tree ((1 2) (3 4) (5 6)) returned by COPY-TREE and the original tree itself are the numbers 5, 6, and the symbol NIL.

I find it confusing because I suppose the numbers 1, 2, 3 and 4 are commonly referenced too. Since numbers are immutable.

Am I wrong in my assumption?

If so, then why aren't the numbers 1, 2, 3 and 4 commonly referenced?

No correct solution

OTHER TIPS

What it means is the every cons cell in the source is not referenced but made fresh in the result. Everything not cons is just referenced.

Yes numbers are immutable, but low numbers that fit in a pointer is not actually an object since the data is encoded in the address. In any case the "pointer address" in the car and cdr is just copied onto a new cons in copy-tree as long as it's not itself a cons cell.

copy-list is the same except it only does fresh cons for cdr and not for additional structure in car. It's just referenced even when it's just cons.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top