Held Tuesday, November 5, 2002
Today we investigate mechanisms for reading input in Scheme. We also revisit Scheme's primary mechanisms for generating output.
;;; Procedure: ;;; merge-colors-1 ;;; Parameters: ;;; color1, a color ;;; color2, a color ;;; Purpose: ;;; To merge color1 and color2 into a new color by using the red ;;; component of the first color, the green component of the second ;;; color, and the average blue component of the two colors. ;;; Produces: ;;; newcolor, the merged color ;;; Preconditions: ;;; Each color is a list of three integers in the range [0..255] ;;; The three integers represent red, green, and blue components of ;;; the color. ;;; Postconditions: ;;; newcolor is a list of three integers in the range [0..255] ;;; (define merge-colors-1 (lambda (color1 color2) (let ((red1 (car color1)) (red2 (car color2)) (green1 (cadr color1)) (green2 (cadr color2)) (blue1 (caddr color1)) (blue2 (caddr color2))) (list red1 green2 (trunc (/ (+ blue1 blue2) 2))))))
read, which reads one Scheme value, skipping whitespace as appropriate.
read-char, which reads a single character for input.
readis an interesting procedure. In many cases, it will continue to read for more than one line.
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Dec 2 08:41:43 2002.
The source to the document was last modified on Tue Sep 3 23:13:32 2002.
This document may be found at