The Seasoned Schemer: Intersectall (page 49)

180 Views Asked by At

At page 49 of The Seasoned Schemer, I can't understand what is going on in the following code (lines 14-16):

(define intersectall
  (lambda (lset)
    (letcc hop
      (letrec
        ((A (lambda (lset)
              (cond ((null? (car lset)) (hop '()))
                    ((null? (cdr lset)) (car lset))
                    (else (I (car lset)
                             (A (cdr lset)))))))
         (I (lambda (s1 s2)
              (letrec
                ((J (lambda (s1)
                      (cond ((null? s1) '())
                            ((member? (car s1) s2) (J (cdr s1)))  ; (14)
                            (else (cons (car s1)                  ; (15)
                                        (J (cdr s1))))))))        ; (16)
                 (cond ((null? s2) '())
                       (else (J s1)))))))
         (cond ((null? lset) '())
               (else (A lset)))))))

My doubt is at line 14:

((member? (car s1) s2) (J (cdr s1)))

If (car s1) is a member of s2, shouldn't it be consed into the result? Similarly, at lines 15 and 17:

(else (cons (car s1) (J (cdr s1))))))))

If it's not a member of s2, shouldn't it be skipped not consed into the result?

1

There are 1 best solutions below

2
Victor Ribeiro On BEST ANSWER

Nevermind... it was an error:

http://www.ccs.neu.edu/home/matthias/BTSS/errata.html

Chapter 13

Page 49: A4: Swap answers of the last two clauses of J's cond

Page 50: Q2: Swap answers of the last two clauses of J's cond