Nov 18
Making a circular list
How would you go about writing a function that converts a given list into a circular one? Obviously the last cons cell of the list must be made to point back to the first cons (conveniently ignoring some special cases like empty and improper lists).
(DEFUN CIRCULARIZE (LIST) (RPLACD (LAST LIST) (FIRST LIST)) LIST)
That doesn’t quite cut it as this test expression shows:
;; Expecting #1=(#\a #\e #\i #\o #\u . #1#) (LET ((*PRINT-CIRCLE* T)) (WRITE (CIRCULARIZE (COERCE "aeiou" 'LIST)))) => (#\a #\e #\i #\o #\u . #\a)
Filed under //
conses
