Created
July 15, 2019 23:37
-
-
Save bitmappergit/d1e284af8291505caff0d43454ca98c2 to your computer and use it in GitHub Desktop.
This file contains 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
(defvar *list* '((1 "Harry Potter And The Half Blood Prince") | |
(0 "Harry Potter And The Chamber Of Secret") | |
(3 "Healthy Eaters") | |
(0 "Hardship Posting") | |
(1 "Vogue Patterns") | |
(4 "The Kirbhiz Pattern") | |
(2 "Stromy Weather"))) | |
(defun all-positions (needle haystack) | |
(loop | |
for element in haystack | |
and position from 0 | |
when (eql element needle) | |
collect position)) | |
(defun sort-list (list) | |
(sort list #'< :key #'car)) | |
(defun substringp (needle haystack &key (test 'char=)) | |
(search (string needle) | |
(string haystack) | |
:test test)) | |
(defun string-contains (string substring) | |
(if (equal (substringp substring string) nil) | |
nil | |
t)) | |
(defun string-does-not-contain (string substring) | |
(if (equal (substringp substring string) nil) | |
t | |
nil)) | |
(defun check-item (list search) | |
(string-contains (car (last list)) search)) | |
(defun check-not-item (list search) | |
(string-does-not-contain (car (last list)) search)) | |
(defmacro search-list (list search test) | |
`(map 'list | |
#'(lambda (x) (,test x ,search)) | |
,list)) | |
(defmacro get-search-results (list search test) | |
`(map 'list | |
#'(lambda (x) (nth x ,list)) | |
(all-positions t (search-list ,list ,search ,test)))) | |
(defun flatten-results (a b) | |
`(,@a ,@b)) | |
(defun search-list-and-sort (list search) | |
(flatten-results (sort-list (get-search-results list search check-item)) | |
(sort-list (get-search-results list search check-not-item)))) | |
(defun print-results (results) | |
(map 'list | |
#'(lambda (x) (pprint (car (last x)))) | |
results)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment