This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ;; This buffer is for notes you don't want to save, and for Lisp evaluation. ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer. #| ====== LAB 7 ====== | | Author(s): | Lab Section: | |# ;;;; Utility Functions ;; Reloads the current file. (define (reload) (load "lab7.scm") ; Change file name if copied to a new file. ) ;; Square (define (square x) (* x x)) ;; REMINDER: ;; You must include test cases for all procedures you write. ;; No credit will be given without test cases showing working code. ;; ;; This lab gives specific instructions for testing the code. ;; These are minimum requirements, but you may do further tests as needed. ;; Use define to store the results of your tests so they can be used in future steps. ;; ;; Read through the lab writeup for full instructions and hints on how to approach this lab. ;;;; ;;;; Step 1 - Getting Warmed Up ;;;; (define (accumulator combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulator combiner null-value term (next a) next b)))) (define (next x) (+ x 1)) (define (square x) (* x x)) (define (power x) (* x 2)) (define (compose f g) (lambda (x) (f (g x)))) (define (repeat f n) (if (< n 2) (lambda (x) (f x)) (compose f (- n 1)))) ;; 1.32 Iterative Solution (define (accumulatori combiner null-value term a next b) (define (help a b counter) (if (> a b) counter (help (+ a 1) b (combiner (term a) counter))))(help a b null-value)) (define (less x) (- x 1)) ;; Recursive accumulate procedure from Lab 5: ;; Test Code (display "--- STEP 1 - Integers From 1 to 10 ---") (newline) (display (accumulator cons () next 0 next 9))(newline) (display "--- STEP 1 - Squares of Integers From 23 pto 28 ---") (newline) (display (accumulator cons () square 23 next 28))(newline) (display "--- STEP 1 - Powers of 2 from 2 to 4096 ---") (newline) (display (accumulator cons () power 1 power 2048)) (newline) (display "--- STEP 1 - Integers from 1 to 10 (Iterative) ---") (newline)...
View Full 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.
- Fall '08