;; /home/comp212/Labs/lab4/sum.ss ;; By Dan Grossman, 96.Sep.30 ;; ;; Some examples showing innacuracies using floating-point numbers, ;; and how to try to get around them. ;; (define make-list (lambda (n s) (if (zero? n) null (cons s (make-list (sub1 n) s))))) (define a (make-list 101 5)) ; b: 1.0e16 followed by 101 5's ; c: 101 5's followed by 1.0e16 ; d: 50 5's followed by 1.0e16 followed by 51 5's ; e: 1.0e16 followed by 50 5's (define b (cons 1.0e16 a)) (define c (append a (cons 1.0e16 null))) (define d (append (make-list 50 5) (cons 1.0e16 (make-list 51 5)))) (define e (cons 1.0e16 (make-list 50 5))) (define sum (lambda (l) (cond ((null? l) 0) (else (+ (car l) (sum (cdr l))))))) (define bsum (sum b)) (define csum (sum c)) (define dsum (sum d)) (define esum (sum e)) (define Best-Sum (lambda (alon) (sum (Sort alon)))) (define Sort (lambda (alon) (cond ((null? alon) null) (else (Insert (car alon) (Sort (cdr alon))))))) ;(define Insert ; (lambda (n aslon) ;; ** HERE'S YOUR JOB! ** ; )) ; uncomment after you write Insert ;(define bsum2 (Best-sum b)) ;(define csum2 (Best-sum c)) ;(define dsum2 (Best-sum d)) ;(define esum2 (Best-sum e)) ; ;; What is the difference between bsum and bsum2?