; A form we did not use in class (define n-list-sum (lambda (nlist) (apply + (map num-exp-sum nlist)))) (define num-exp-sum (lambda (exp) (if (number? exp) exp (n-list-sum exp)))) ; Starting point for class (define n-list-sum (lambda (nlist) (cond [(null? nlist) 0] [(number? (car nlist)) (+ (car nlist) (n-list-sum (cdr nlist)))] [else (+ (n-list-sum (car nlist)) (n-list-sum (cdr nlist)))]))) ; Add counter and print it every time procedure is called (define n-list-sum (let ([count 0]) (lambda (nlist) (set! count (+ 1 count)) (display (format "~s " count)) (cond [(null? nlist) 0] [(number? (car nlist)) (+ (car nlist) (n-list-sum (cdr nlist)))] [else (+ (n-list-sum (car nlist)) (n-list-sum (cdr nlist)))])))) ; Print the counter only when procedure is called with no arguments (define n-list-sum (let ([count 0]) (case-lambda [(nlist) (set! count (+ 1 count)) (cond [(null? nlist) 0] [(number? (car nlist)) (+ (car nlist) (n-list-sum (cdr nlist)))] [else (+ (n-list-sum (car nlist)) (n-list-sum (cdr nlist)))])] [() count]))) ; Go into the debugger after the 100000th call (the number cen be reset). ; second argument is not actually used; it is there to distinguish ; this case frm the other case-lambda cases (define n-list-sum (let ([count 0] [break-number 100000]) (case-lambda [(nlist) (set! count (+ 1 count)) (if (= count break-number) (break)) (cond [(null? nlist) 0] [(number? (car nlist)) (+ (car nlist) (n-list-sum (cdr nlist)))] [else (+ (n-list-sum (car nlist)) (n-list-sum (cdr nlist)))])] [() count] [(break-count dummy) (display "Setting break-number ~%") (set! break-number break-count)])))