;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname inexact) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;; Sample code to explore the computations
;; with inexact numbers
;; Also explore two different ways of implementing loops
;; that traverse over a list of data
;; 28 August 2013
(define NUM-LIST (list #i+9e23 #i+8e23 #i-1e23 #i+6e23))
(define (sum-right alist)
(foldr + 0 alist))
(define (sum-left alist)
(foldl + 0 alist))
;; one way to add all numbers
(sum-right NUM-LIST)
;; another way to add all numbers
(sum-left NUM-LIST)
(check-within (sum-right NUM-LIST) #i2.2e+24 #i0.001e+24)
(check-within (sum-left NUM-LIST) #i2.2e+24 #i0.001e+24)