'Every solution that I've seen for SICP Exercise 3.16 appears to cheat by creating more than three pairs. Where is my misunderstanding?

SICP Exercise 3.16 gives the reader a broken procedure for counting the numbers of pairs in a list structure:

(define (count-pairs x)
  (if (not (pair? x))
      0
      (+ (count-pairs (car x))
         (count-pairs (cdr x))
         1)))

It then challenges the reader to create list structures made up of exactly three pairs that make this procedure return:

  1. 3
  2. 4
  3. 7
  4. Never return.

Tasks #1 and #4 are easy; Just make a normal list of three elements and make a circular list. For tasks #2 and #4, however, every solution that I've seen appears to cheat by creating more than three pairs. For example, the Scheme Wiki gives these:

 (define x '(foo)) 
 (define y (cons x x)) 
 (define str2 (list y)) 
 (count-pairs str2) ; 4 

 (define x '(foo)) 
 (define y (cons x x)) 
 (define str3 (cons y y)) 
 (count-pairs str3) ; 7

 (define second (cons 'a 'b)) 
 (define third (cons 'a 'b)) 
 (define first (cons second third)) 
 (set-car! third second) 
 (count-pairs first)  ;; => 4 
  
 (define third (cons 'a 'b)) 
 (define second (cons third third)) 
 (define first (cons second second)) 
 (count-pairs first)  ;; => 7 

I disagree with all of them for the same reason: They appear to be more than three pairs. For example, the final list from the first block of code will be (cons (cons (cons 'foo nil) (cons 'foo nil)) nil). As I've written cons more than three times, this isn't made of three pairs. Similarly, the last block is clearly (cons (cons (cons 'a 'b) (cons 'a 'b)) (cons (cons 'a 'b) (cons 'a 'b))), which is far more than three pairs.

Where is my misunderstanding?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source