Lines are a bit annoying to work with, so we wrap it around a work function that processes lists. In this way, we can avoid unrest throughout the world.
(define (remove-repeats str)
(list->string (remove-repeats/list (string->list str))))
Now we can define the remove-repeat / list function using direct recursion:
(define (remove-repeats/list xs)
(cond
[(empty? xs) xs]
[(empty? (cdr xs)) xs]
[(equal? (car xs) (cadr xs)) (remove-repeats/list (cdr xs))]
[else (cons (car xs) (remove-repeats/list (cdr xs)))]))
, :
(define (remove-repeats str)
(list->string (remove-repeats/list-acc (string->list str) '())))
(define (remove-repeats/list-acc xs acc)
(cond
[(empty? xs) (reverse acc)]
[(empty? (cdr xs)) (reverse (cons (car xs) acc))]
[(equal? (car xs) (cadr xs)) (remove-repeats/list-acc (cdr xs) acc)]
[else (remove-repeats/list-acc (cdr xs) (cons (car xs) acc))]))