Skip to content

Instantly share code, notes, and snippets.

@schmalz
Created July 27, 2022 10:44
Show Gist options
  • Save schmalz/f2d494bd3e92a8eebf0deeaef32527b8 to your computer and use it in GitHub Desktop.
Save schmalz/f2d494bd3e92a8eebf0deeaef32527b8 to your computer and use it in GitHub Desktop.
;;; 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))
@schmalz
Copy link
Author

schmalz commented Jul 27, 2022

From Common Lisp: A Gentle Introduction to Symbolic Computing - the mini keyboard exercise 6.26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment