;; 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-advanced-reader.ss" "lang")((modname lect05c-accumulator) (read-case-sensitive #t) (teachpacks ((lib "world.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "world.ss" "teachpack" "htdp"))))) (define (sum-all lon) (cond [(empty? lon) 0] [(cons? lon) (+ (first lon) (sum-all (rest lon)))])) #;(sum-all empty) #;(sum-all (list 2 3 4 5 6 7 8 9 10 11)) (define (sum-all-v2 lon) (sum-all-helper lon 0)) ; Return the sum of all elements in lon, plus ssf. (define (sum-all-helper lon ssf) (cond [(empty? lon) ssf] [(cons? lon) (sum-all-helper (rest lon) (+ (first lon) ssf)) ])) (sum-all-v2 empty) (sum-all-v2 (list 2 3 4 5 6 7 8 9 10 11))