Suppose we wish to remove adjacent duplicate elements from a list (e.g., after sorting). The following Scheme

Question:

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

(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)))))))

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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Programming Language Pragmatics

ISBN: 9780124104099

4th Edition

Authors: Michael L. Scott

Question Posted: