Function won't recurse?!!
Posted: Sat Mar 22, 2014 2:47 pm
This has been driving me crazy for the last hour and a half. I know that I'm probably going to kick myself in the head when I know the answer, but here:
The function returns the head of the list, then stops:
I also wanted to know if there was a better way of constructing the list that would be better than my method, but for right now I'd settle for an answer to this. I know it's something simple, I just can't see it. Danke.
Code: Select all
(defun dotted-pair(lst) ; lst:= a list
(labels ((dp (i lst)
(if (or (eq lst nil) (not (eq (mod (list-length lst) 2) 0)))
nil
(append (list (cons (first lst) i)) (dp (1+ i)(rest lst))))))
(dp 1 lst)))
Code: Select all
(dotted-pair ()) ; => nil
(dotted-pair '(a b c) ; => nil
(dotted-pair '(v x y z) ; => ((V.1))