Warning: do not try this with XLISP:
> (setq my-list (cons 'item nil)) ; create a 1-item list (ITEM) > (setf (cdr my-list) my-list)) ; create the circle ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ITEM ...
If you're lucky you can break the
loop.
The '
(defmacro c-nth (index list) `(nth ,(rem index (length list)) ,list))
Note that with every call to '
Examples:
(c-nth 0 '(1 2 3)) => 1 (c-nth 1 '(1 2 3)) => 2 (c-nth 2 '(1 2 3)) => 3 (c-nth 3 '(1 2 3)) => 1 (c-nth 4 '(1 2 3)) => 2 (c-nth 5 '(1 2 3)) => 3 (c-nth 6 '(1 2 3)) => 1 (c-nth 7 '(1 2 3)) => 2Because '
(setq lst '(1 2 3)) => (1 2 3) lst => (1 2 3) (setf (c-nth 4 lst) 'x) => X lst => (1 X 3)