From time to time, I find myself wanting to use MAPCAR where the function would like to make use of the index. I've done it in some kind of stupid ways in the past, and then came up with this:
Code: Select all
(defun make-counter ()
(let ((count 0))
(lambda ()
(prog1 count (incf count)))))
(defun make-counter-circle ()
(alexandria:make-circular-list 1 :initial (make-counter)))
(mapcar (lambda (n x)
(list (funcall n) x))
(make-counter-circle)
'(a b c d e f g))
=> ((0 A) (1 B) (2 C) (3 D) (4 E) (5 F) (6 G))
Is this sensible? A known pattern? A world-changing work of inspired genius? "Not even wrong"?