armedbear / abcl

Armed Bear Common Lisp <git+https://github.com/armedbear/abcl/> <--> <svn+https://abcl.org/svn> Bridge
https://abcl.org#rdfs:seeAlso<https://gitlab.common-lisp.net/abcl/abcl>
Other
291 stars 29 forks source link

Circular lists #611

Closed mnepveu closed 1 year ago

mnepveu commented 1 year ago

An infinite loop is entered when attempting to create a circular list.

Environment: Armed Bear Common Lisp 1.9.3-dev Java 1.8.0_342 Temurin OpenJDK 64-Bit Server VM

Examples:

(defun circularlist (items)
  (setf (cdr (last items)) items)
  items)

(circularlist (list 1 2 3))

Or using Alexandria:

(ql:quickload :alexandria)
(alexandria:make-circular-list 1 :initial-element 1)
easye commented 1 year ago

Both your function circularlist and your use alexandria:make-circular-list loop forever on SBCL, ECL, and CCL as well, so I think there is a more fundamental issue going on that doesn't work with the semantics of Common Lisp in general. I must confess that having ALEXANDRIA's inferface not work surprises me as it is a ruggedly battle-tested library.

Closing this issue for now, but if you have more information on what you are trying to do OR if you find code that works on another implementation that works on the Bear, I would be happy to revisit.

alanruttenberg commented 1 year ago

Try setting *print-circle* to t

CL-USER> (setq *print-circle* t)
t
CL-USER> (alexandria:make-circular-list 1 :initial-element 1)
#1=(1 . #1#)
CL-USER> (defun circularlist (items)
  (setf (cdr (last items)) items)
  items)
circularlist
CL-USER> (circularlist (list 1 2 3))
#1=(1 2 3 . #1#)