Created
July 27, 2022 10:44
-
-
Save schmalz/f2d494bd3e92a8eebf0deeaef32527b8 to your computer and use it in GitHub Desktop.
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
;;; Compare descriptions of two objects and report the number of common features. Descriptions are lists of features | |
;;; separated by the symbol -VS- (e.g. (large red shiny cube -vs- small shiny red four-sided pyramid)). | |
(defun right-side (descriptions) | |
"The features of the object to the right of the separator." | |
(cdr (member '-vs- descriptions))) | |
(defun left-side (descriptions) | |
"The features of the object to the left of the separator." | |
(right-side (reverse descriptions))) | |
(defun count-common (descriptions) | |
"The number of features the two objects have in common." | |
(length (intersection (left-side descriptions) | |
(right-side descriptions)))) | |
(defun compare (descriptions) | |
"Report the number of features that the two objects have in common." | |
`(,(count-common descriptions) common features)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Common Lisp: A Gentle Introduction to Symbolic Computing - the mini keyboard exercise 6.26.