The function is called sublist? with two arguments (both lists). It checks whether l2 is a sublist of l1 and returns #t or #f.
I have this so far, but seems the exists function is not working properly
(define (sublist? l1 l2)
(cond ((null? l2) #t)
((exists l1 (car l2)) #t)
(else (sublist? l1 (cdr l2)))))
(define (exists l p)
(if (null? l) #f
(or (equal? p (car l)) (exists (cdr l) p))))
updated
First of all I think in your
existsfunction, you are missing anequals?And it seems the first parameter is the one that’s supposed to be an atom, but in your sublist function you send the list first and the atom next, you need to switch the parameters.
That should work fine.
Also, its convention to call your predicate functions as a question, you should name it
exists?[Edit]
Also upon closer inspection, it looks like your sublist? function is incorrect. It will return #t even if only one element of the sublist exists in the list. You need to modify it a bit into:
Now you are saying:
1) Is empty? Then is a sublist.
2) Is this element NOT in the list? Then is not.
3) If it is, then check the rest of the elements.