問題3.17

(define (count-pairs-2 x)
  (define counted-pairs '())
  (define (add-pair! p)
    (set! counted-pairs (cons p counted-pairs)))
  (define (already-counted? p)
    (memq p counted-pairs))
  (define (iter x)
    (if (or (not (pair? x)) (already-counted? x))
        0
        (begin
          (add-pair! x)
          (+ (iter (car x))
             (iter (cdr x))
             1))))
  (iter x))

;;3.16すべての場合でok