0

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...

Makketronix
  • 1,389
  • 1
  • 11
  • 31

1 Answers1

2

It's not the reader, but the printer that is in an infinite loop.
Most implementations have a variable to limit the top level printer, see *PRINT-LEVEL*, *PRINT-LENGTH*

Barmar
  • 741,623
  • 53
  • 500
  • 612
ddyer
  • 1,792
  • 19
  • 26