Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sublists in Scheme/Racket

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...

 (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))))

Name: Anonymous 2012-11-08 16:26

>>7
Is that you, Ahmed?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List