I am trying to understand why this produces what seems to be circular list.
* (progn
(setf (car *x*) (append '(3) *x*))
2)
2 ;; No "apparent issue setting the value. Hence it is related to printing `*x*`
*x* ;; infinite loop, perhaps due to the structure of *x*??
Why is it a circular list? I would expect that it should not be a circular list
What is different between this question and the "duplicate" question:
In this question, I believe *x*
should not be a circular list. In the duplicate answer chain, it is shown how to create a circular list, and neither of the example uses the result of append
in the setf
.
Alright, I found the answer: My confusion arises from misunderstanding the spec where they say that append returns a new list.
Evidently a new list does not mean that each and every member of it is new (does not mean a copy is returned). The last argument of append is actually shared...