I want to map over a list, but keeping track of the element index in the list.
In Python I can do something along the lines of:
map(lambda (idx, elt): "Elt {0}: {1}".format(idx, elt), enumerate(mylist))
I was trying to translate it to something along the lines of:
(mapcar-something (lambda (elt idx) (format nil "Elt ~D: ~S" idx elt))
'(a b c d))
Expected result:
("Elt 0: A" "Elt 1: B" "Elt 2: C" "Elt 3: D")
But I can't find the mapcar-something function that I should use. Do I need to implement that myself (via loop, maybe)?
let
block and capture an index variable from the lambda, then increment that each time the lambda is called. I don't think there's a builtin. – Mirepoix