next up previous contents
Next: Retrieving the n-th element Up: Basic utility abstractions for Previous: Determining the length of   Contents


Removing an element from a list: `remove'

This abstraction creates a new list from the given list making sure that the element specified as first argument does not appear in the resulting list returned.


(define remove
  (lambda(obj l)
    (if (nullp l)
        nil
        (if (equalx obj (car l))
            (remove obj (cdr l))
            (cons (car l)  (remove obj (cdr l)))))))


(define l1 (cons one (cons two (cons three (cons four nil)))))
;
(ldisp! (remove three l1))
                          --> 1
                          --> 2
                          --> 4



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz