Hi. I'm completely new to Common Lisp and trying to learn something about functional programming . I'm using SBCL on OS X with Emacs/Slime. I'm trying to do the exercises of Paul Graham's book, ANSI Common Lisp, and there's one that it seams to be ok to me but it doesn't give the right answer. Exercise 3-5 asks for a recursive function that takes a list and returns another list of each element plus its position. So,
- Code: Select all
> (pos+ '(7 5 1 4))
(7 6 3 7)
My code is bellow, and when I call the function with the same list above the answer is only (7). Can anyone tell me what I'm doing wrong?
- Code: Select all
(defun pos+ (lst)
(pos-rec lst 0 ()))
(defun pos-rec (lst i result)
(if lst
(progn (push (+ (car lst) i) result)
(pos-rec (cdr lst) (+ i 1) result)))
result)
