(define (delete-doubles lst)
(cond ((null? lst) '())
((null? (cdr lst)) (car lst))
((equal? (car lst) (cadr lst)) (delete-doubles (cdr lst)))
(else (cons (car lst) (delete-doubles (cdr lst))))))
This is the code I made. It is meant for deleting an element in a list when this element shows up two or more times after each other. The code works totally fine, apart from this:
> (delete-doubles '(1 2 2 3 4 5))
(1 2 3 4 . 5)
I'd like to remove the .
, and I know it has something to do with the cons
, but I don't know how to solve it.
Thanks in advance.
when the cdr is null you are just returning the car, and in the else line you are doing cons on car and recursion on cdr. So that is where your pair is coming from. Does that help?