Created
April 25, 2012 04:31
-
-
Save fadeev/2486368 to your computer and use it in GitHub Desktop.
ANSI Common Lisp (exercises)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Exercise 3.2, p. 56 | |
| (defun union-in-order (&rest lists) | |
| "Returns a union of lsts, preserving the order" | |
| (remove-duplicates (reduce #'append lists) | |
| :from-end t | |
| :test #'equal)) | |
| ;; Exercise 3.3, p. 56 | |
| (defun sort-by-frequency (list) | |
| "Returns sorted by frequency alist of occurrences, | |
| e.g. '(a a b a c c) -> '((A .3) (C . 2) (B . 1))" | |
| (sort (mapcar #'(lambda (x) `(,x . ,(count x list :test #'equal))) | |
| (remove-duplicates list :test #'equal)) | |
| #'> | |
| :key #'cdr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment