Question: Suppose we wish to remove adjacent duplicate elements from a list (e.g., after sorting). The following Scheme function accomplishes this goal: Write a similar function
Suppose we wish to remove adjacent duplicate elements from a list (e.g., after sorting). The following Scheme function accomplishes this goal:

Write a similar function that uses the imperative features of Scheme to modify L “in place,” rather than building a new list. Compare your function to the code above in terms of brevity, conceptual clarity, and speed.
(define unique (lambda (L) (cond ( (null? L) L) ( (null? (cdr L)) L) ((eqv? (car L) (car (cdr L))) (unique (cdr L))) (else (cons (car L) (unique (cdr L)))))))
Step by Step Solution
3.45 Rating (171 Votes )
There are 3 Steps involved in it
Heres an imperative version The code is slightly longer Which version is conc... View full answer
Get step-by-step solutions from verified subject matter experts
