;; A Grocery-List is one of ;; - empty ;; - (cons Symbol Grocery-List) ;; Grocery-List examples (define gl1 empty) (define gl2 (cons 'eggs (cons 'beer (cons 'bread empty)))) (define gl3 (cons 'milk empty)) ;; count-items : Grocery-List -> Number ;; counts how many items are on a grocery list #| Template (define (count-items gl) (cond [(empty? gl) ... ] [(cons? gl) ... (first gl) ... ... (count-items (rest gl)) ... ])) |# (define (count-items gl) (cond [(empty? gl) 0] [(cons? gl) (+ 1 (count-items (rest gl)))])) ;; Examples/tests (= (count-items gl1) 0) (= (count-items gl2) 3) (= (count-items gl3) 1)