I'm trying to make something that iterates through two lists, matching the contents - though not the sequence - of the former against the latter returning true or false depending on whether it finds a match.
Code: Select all
(defun included (list lof-l)
(if (not (eq (car list) (car lof-l))) ;; If car lst isn't car lof-l then
(if (not (eq lof-l 'nil)) ;; If the second list isn't empty then
(included list (cdr lof-l)) ;; Go to the next symbol in second list
(if (not (eq list 'nil)) ;; If you're out of symbols in the second list
(included (cdr list) lof-l) ;; Go back to the start and go to the next symbol in the first list - no work!
'nil) ;; If you're out of symbols in the first list, you're finished
't)) ;; If the symbol matches the symbol in the 2nd list you're finished
I could keep track of the original form of lof-l as a global variable, or I could pass it down as a third variable in the function declaration, but both of those feel a bit off. The former because I can't see any other use for the thing, the latter because it seems odd to make someone input something twice.
I'm wondering if there's a more elegant way to have my lists and eat them. ^^;