;; This file contains excerpts from the textbook Concrete ;; Abstractions: An Introduction to Computer Science Using Scheme, by ;; Max Hailperin, Barbara Kaiser, and Karl Knight, Copyright (c) 1998 ;; by Brooks/Cole Publishing Company. This file may not be reproduced ;; or redistributed other than for use with that textbook. (define from-to-do (lambda (start stop body) (if (> start stop) 'done (begin (body start) (from-to-do (+ start 1) stop body))))) (define display-price (lambda (amount-as-cents) (display "$") (display (quotient amount-as-cents 100)) (display ".") (if (< (remainder amount-as-cents 100) 10) (display "0")) (display (remainder amount-as-cents 100)))) (define input-integer-in-range (lambda (min max) (display "(enter ") (display min) (display "-") (display max) (display ")") (newline) (let ((input (read))) (cond ((not (integer? input)) (display "input must be an integer and wasn't") (newline) (input-integer-in-range min max)) ((or (< input min) (> input max)) (display "input out of range") (newline) (input-integer-in-range min max)) (else input))))) (define input-selection (lambda (choices) (define display-loop (lambda (number choices) (if (null? choices) 'done (begin (display " ") (display number) (display ") ") (display (car choices)) (newline) (display-loop (+ number 1) (cdr choices)))))) (display-loop 1 choices) (list-ref choices (- (input-integer-in-range 1 (length choices)) 1)))) (define input-item (lambda () (display "What would you like?") (newline) (display " 1) Chinos") (newline) (display " 2) Oxford-cloth shirt") (newline) (if (= (input-integer-in-range 1 2) 1) (make-chinos) (make-oxford-shirt))))