4 10 Points Define Scheme Function Takes Two List Representing Sets Returns List Represent Q37064408

4. 10 points

Define a Scheme function that takes two list representing setsand returns a list representing the intersection of the sets.

Example: (intersection (list 3 1 2 4) (list 4 2 86)) (2 4)

5. 20 points

Define set-equal? which takes two lists representing sets andreturns true iff they represent the same set.

Example: (set-equal? ’(1 2 3) ’(2 1 3)) #t

              (set-equal? ’ (1 2 () 3) ’(2 1 3)) ⇒#f


Answer


Answer4:

;Answer 4: Define a Scheme function that takes two listrepresenting sets and returns a list representing the intersectionof the sets.

(define intersection

(lambda (s1 s2)

(cond ((null? s1) ‘())

((member (car s1) s2)

(cons (car s1)

(intersection

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.