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

; add-up : list-of-numbers -> number
(check-expect (add-up empty) 0)
(check-expect (add-up (cons 14 empty)) 14)
(check-expect (add-up (cons 3 (cons 4 empty))) 7)
(check-expect (add-up (cons 4 (cons 8 (cons -3 empty)))) 9)

(define (add-up L)
  ; L a lon
  (cond [(empty? L) 0]
        [(cons? L) (add-up-nelon L)]
        ))
(define (add-up-nelon L)
  ; L                 nelon       (cons 4 (cons 8 (cons -3 empty)))
  ; (first L)         number      4
  ; (rest L)          lon         (cons 8 (cons -3 empty))
  ; (add-up (rest L)) number      5
  ; right answer      number      9
  (+ (first L) (add-up (rest L)))
  )
#|
; Alternative version, all in one function
(define (add-up L)
  ; L lon
  (cond [(empty? L) 0]
        [(cons? L)
         ; L nelon
         ; (first L) number
         ; (rest L) lon
         ; (add-up (rest L)) number
         (+ (first L) (add-up (rest L)))
         ]))
|#