;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; root.ss ;;; A scheme program that prompts for values and prints ;;; their square roots. ;;; Author: Samuel A. Rebelsky ;;; Version: 1.0 ;;; Created: Tuesday, 26 September 2000 ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Procedures ;;; interactive-square-root ;;; Repeatedly prompts for a number and prints its square root ;;; Parameters: None ;;; Preconditions: None ;;; Postconditions: Has read values from input. Prints output. ;;; Produces: Nothing (define interactive-square-root (lambda () (display "Enter a number (or quit to quit): ") (isr-helper (read)))) ;;; isr-helper ;;; Helper procedure for interactive-square-root ;;; Checks the value entered and does something appropriate ;;; Parameters: The value entered (define isr-helper (lambda (val) (if (not (number? val)) (quit) (begin (display "The square root of ") (display val) (display " is ") (display (sqrt val)) (newline) (interactive-square-root))))) ;;; quit ;;; Display a goodbye message. (Doesn't really quit.) ;;; Parameters: None ;;; Preconditions: None ;;; Postconditions: Has displayed text. ;;; Produces: Nothing (define quit (lambda () (display "Bye!") (newline))) ;;; print-root ;;; Displays information about the square root of a value ;;; Parameters: A value ;;; Preconditions: The value is a number. (NOT CHECKED!) ;;; Postconditions: Has displayed helpful text. ;;; Produces: Nothing (define print-root (lambda (value) (display "The square root of ") (display value) (display " is ") (display (sqrt value)) (newline))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Run the program (interactive-square-root)