This question already has an answer here:
- Circular list in Common Lisp 3 answers
I want to make circular list with common lisp using rplaca or rplacd.
lambda (x) (cons (car x) (cons (rplacd (cdr x) (car x))))
I made code like above, but i think it is not what I want to. How I make circular list?
First of all, you will always get a stack overflow when you try to print a circular object and
*print-circle*
isnil
. So, start withNow, there are many ways to create a circular list:
Note how the circular list is printed with
#=
so that it can beread
:Warning:
(equal *my-circular-list* *my-circular-list-1*)
will hang because it will infinitely descend into the circular structures.You can also try this: