I store graph coordinates in a circular list:
(defun make-circular-list (size &key initial-element)
(let ((list (make-list size :initial-element initial-element)))
(nconc list list)))
(defvar *coordinates* (make-circular-list 1024 :initial-element 0.0))
Now it’s easy to update *coordinates* whenever new coordinates must be set.
However, I have a library function that takes a sequence of coordinates to draw lines on a graph. Of course this function does not work with a circular structure, so I would like to make a copy of fixed length. A list or an array is fine.
So far I have tried subseq and make-array with the :initial-contents keyword, but it fails. loop or dotimes do work but I was hoping to avoid iterating on each elements of the list.
Is it possible to efficiently copy this circular structure or make a fixed length array in the spirit of a displaced-array?
There is nothing wrong with using LOOP.
Btw., sometimes it might be useful to hide the circular list behind a CLOS object.
And so on…
That way you can provide some CLOS methods for accessing and changing it (create, add, copy, delete, , as-list, …). You can also control printing of it using a method for
PRINT-OBJECT.