So I have this program that needs to be written in Scheme using Racket that has the following properties and I am stumped. The function is called sublist?
with two inputs of S
and L
which are both lists. It checks whether S is a sublist of L
and returns #t
or #f
.
Examples would be similar to:
sublist? of (A A) and (A B C) is #f
sublist? of (A B C) and (A B D A B C D) is #t
sublist? of (A (B)) and (C ((A (B))) (C)) is #t
A small function called extractLists
needs to be created to extract the lists and (atomicSublist S L)
is used to check the two extracted lists to see if every element of S
is in L
.
So far I have
(define (atomicSublist S L)
(cond ((null? L) #f)
((equal? S (car L)) #t)
(else (atomicSublist S (cdr L)))))
The second part does not really do anything and doesn't even output the extracted value of S.
Updated code:
Just for testing I use atomicSublist
to check for now.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…