I want to write a function in lisp that takes two lists of pairs and removes all occurrences of the first list from the second list.
As an example, if we have list1 ((a b)(cd)) and list2 ((g h)(a b)(j i)), by calling this function the result would be ((g h)(j i)).
Until now i have the following code (which is not working):
(defun retira(obj l1)
(cond ((null l1) ())
((equal obj (first l1)) (retira obj (rest l1)))
(t (cons (first l1) (retira obj (rest l1))))))
(defun retira-ocupadas (tabuleiro lista-adj)
(if (equal (first (todos-ocupados tabuleiro)) (first lista-adj))
(retira (car (todos-ocupados tabuleiro)) lista-adj))
(retira-ocupadas (rest (todos-ocupados tabuleiro)) (rest lista-adj)))
Where retira should remove all occurrences of an object in a list and retira-ocupadas should take care of comparing, if the object from the first list is equal to an object from the second list. Todos-ocupados is a function that generates the first list.
This is currently not working, what am I doing wrong ?
You want to remove any element of the second list that is a member of the first.
Please note the definition of
equal, perhaps you wantequalpinstead (or perhaps you need to write your ownpair-equal).