Name: Anonymous 2012-11-08 15:50
/prog/
What am I doing wrong here?
I'm supposed to make a Scheme/Racket function named "sublist?" that takes 2 lists of numbers. It is supposed to produce true if list1 is a sublist of list2 (in other words, list 2 contains list1) and false if its otherwise.
But this shit ain't working...
What am I doing wrong here?
I'm supposed to make a Scheme/Racket function named "sublist?" that takes 2 lists of numbers. It is supposed to produce true if list1 is a sublist of list2 (in other words, list 2 contains list1) and false if its otherwise.
But this shit ain't working...
(define (sublist? l1 l2)
(cond ((null? l2) #t)
((not (exists l1 (car l2))) #f)
(else (sublist? l1 (cdr l2)))))
(define (exists l p)
(if (null? l) #f
(or (equal? p (car l)) (exists (cdr l) p))))