The Marker

Exercises

Write a version of union that preserves the order of the elements in the original lists:

> (new-union '(a b c) '(b a d))
(A B C D)

>(defun new-union (lst1 lst2)
    (let ((newlist ()))
        (dolist (elm lst2)
            (if (null (member elm lst1))
                (setf newlist (append newlist (list elm)))))
        (append lst1 newlist)))

NEW-UNION

>(new-union '(a b c) '(b a d))

(A B C D)

Define a funciton that takes a list and returns a list indicating the number of times each (eql) element appears, sorted from most common element to least common:

> (occurrences '(abadacdca))
((A . 4) (C . 2) (D . 2) (B . 1))
changed January 3