I'm trying to write a 'member-of' function, to check whether an element is a member of a list or not.
My first attempt, the iterative one, is pretty easy:
If the element isn't, this function will not terminate.
How to fix this?
My first attempt, the iterative one, is pretty easy:
(defun member-of (elem the-list)
(if (eql elem (car (member elem the-list)))
'T
'NIL)
Now I want to make the recursive version.
(defun member-of (elem the-list)
(if (eql elem (car the-list))
'T
(member-of elem (cdr the-list))))
Of course that only works if the element is indeed a member of the list.If the element isn't, this function will not terminate.
How to fix this?