Find an element of list in lists in list

前端 未结 3 1164
野趣味
野趣味 2021-01-28 05:58

I need a procedure which takes a list and checks if an element is part of that list even when the list contains lists. So far, I\'ve written this:

(define (elem         


        
3条回答
  •  不思量自难忘°
    2021-01-28 06:27

    You just need another clause to check if the car is a list. Add this to your cond (after the eq? clause):

    ((list? (car set))
     (or (element-of-set? element (car set))
         (element-of-set? element (cdr set))))
    

    This recurses on any sublists.

提交回复
热议问题