My attempt was,
(define (remove-dup lst)
(cond ((null? lst) '())
((null? (cdr lst)) (car lst))
((equal? (car lst) (car (cdr lst))) (remove-dup (cdr lst)))
(else (cons (car lst) (remove-dup (cdr lst))))
)
)
My list was (a b c a a c c c )
What I want is (a b c)
. Any idea?
Thanks,
I'd approach this by looping with a second list that you build up of seen elements. I'll feel bad for giving this to you if this was homework though - it's more important to understand how recursion works than to just have the right answer.
Updated to accommodate your comments - this probably isn't the cleanest solution but should give you an idea of how it might work.
R5RS + SRFI1
Using SRFI 1 you can use directly
delete-duplicates
ordelete-duplicates!
: http://srfi.schemers.org/srfi-1/srfi-1.html#delete-duplicates