How to remove non-duplicate elements from a list in Scheme?
问题 Given a list, (define ll '(a a a b c c c d e e e e)) I want to remove all non-duplicate elements and leave only one copy of the duplicate one, i.e. after removing, the result would be (a c e) My algorithm is: Traverse through the list, comparing current element with next element. If they're equal, then cons the current element with the list of the next recursive call. For example, (a a a b c) Move from left to right, encounter a and a . (cons a (remove-nondup (cddr lst))) Otherwise, skip