lab5 - #| = LAB 5 = | | Author(s): | Lab Section: | |# ;...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#| ====== LAB 5 ====== | | Author(s): | Lab Section: | |# ;;;; Utility Functions ; ;; Reloads the current file. (define (reload) (load "lab5.scm") ; Change file name if copied to a new file. ) ;; REMINDER: ;; You must include test cases for all procedures you write. ;; Thoroughly test each procedure and be prepared to demonstrate that the code works as expected. w ;;;; ;;;; Step 1 - Using the Sum Abstraction ;;;; ; ;; Sum Abstraction Procedure from Text (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)) ) ) ;; Test Code (display "--- STEP 1 [PART A] TEST CASES ---") (newline) ( (define (inc n) (+ n 1)) (define (sum-sqrt a b) (sum sqrt a inc b) ) (display (sum-sqrt 1 3)) (newline) (display (sum-sqrt 1 100)) (newline) (display (sum-sqrt 1 150)) (newline) ;(display (sum-sqrt 1 40000)) ; (display "--- STEP 1 [PART B] TEST CASES ---") (newline) ( (define (fact x) (if (= x 0) 1 (* x (fact (- x 1)))))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(define (invfact x) (/ 1.0 (fact x))) ( (define (sum-invfact n) (sum invfact 0 inc n) ) (display (sum-invfact 3)) (newline) (display (sum-invfact 100)) (newline) (display (sum-invfact 150)) (newline) ;(display (sum-invfact 0 1500)) ;(newline) ; (newline) (display "--- STEP 1 [PART C] TEST CASES ---") (newline) ( (define (sum2 term a next b) (define (iter a result) (if (> a b) result (iter (next a) (+ (term a) result)) ) ) (iter a 0) ) ; ;(tentinue, call RESTART with an option number: ; (RESTART 10) => Specify a value to use instead of b
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course CSCI 1901 taught by Professor Staff during the Fall '08 term at Minnesota.

Page1 / 7

lab5 - #| = LAB 5 = | | Author(s): | Lab Section: | |# ;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online