;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname 24.3.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
; Worked exercise 24.3.1

; nn-add : whole-num (m) whole-num (n) -> whole-num
(check-expect (nn-add 0 0) 0)
(check-expect (nn-add 0 1) 1)
(check-expect (nn-add 0 3) 3)
(check-expect (nn-add 1 0) 1)
(check-expect (nn-add 3 0) 3)
(check-expect (nn-add 3 8) 11)
(define (nn-add m n)
  (cond [(zero? n) m]
        [(positive? n)
         ; m             whole               3
         ; n             positive whole      8
         ; (sub1 n)       whole               7
         ; (nn-add m (sub1 n))  whole        10
         ; right answer        whole        11
         (add1 (nn-add m (sub1 n)))]))
