that is:

"Suppose the function pos+ takes a list and returns a list of each element plus it's position:

> (pos+ '(7 5 1 4))

(7 6 3 7)

Define this function using (a) recursion, (b) iteration, (c) mapcar."

(a) and (b) are straightforward, but (c) I solved following way:

- Code: Select all
`(defun pos+ (l)`

(let ((i -1)) (mapcar #'(lambda (x) (incf i) (+ x i) )

l )))

I don't like this code, can anybody suggest more elegant solution?

Moreover, I don't understand why

- Code: Select all
`(let ((i -1)) (mapcar #'(lambda (x) (+ x i) (incf i) )`

l )))

doesn't work. Please help because I'm stuck with learning.