;; union-nodup : set-of-numbers set-of-numbers set-of-numbers (define (union-nodup s1 s2) (cond [(null? s1) s2] [else (let ([un (union-nodup (cdr s1) s2)]) (if (number-in-set? (car s1) un) un (cons (car s1) un)))])) ;; number-in-set? number set-of-numbers boolean (define (number-in-set? num set) (cond [(null? set) #f] [else (or (= num (car set)) (number-in-set? num (cdr set)))]))
Hand Evaluate:
(union-nodup (cons 2 (cons 3 '())) (cons 1 (cons 2 '())))
Solution