Functional Problem Solving (CSC 151 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
irgb-add(max v1 v2)
;;; Procedure:
;;; max
;;; Parameters:
;;; v1, a real number
;;; v2, a real number
;;; Purpose:
;;; Takes the maximum value of v1 and v2, whichever is larger
;;; Produces:
;;; result, a real number, the larger of v1 and v2
;;; Preconditions:
;;; [No additional]
;;; Postconditions:
;;; result = v1 or result = v2
;;; result >= v1
;;; result >= v2
;;; Problems:
;;; What happens if the two numbers are equal? We can use
;;; either of them, since that value will meet the postconditions
;;; Process:
(irgb-average color1 color2)
;;; Procedure:
;;; irgb-average
;;; Parameters:
;;; color1, a color
;;; color2, a color
;;; Purpose:
;;; Average the components of color1 and those of color2.
;;; Produces:
;;; avecolor, an integer-encoded RGB color
;;; Preconditions:
;;; color1 and color2 must be integer-encoded RGB colors
;;; Postconditions:
;;; (irgb-red avecolor) = (floor (/ (+ (irgb-red color1) (irgb-red color2)) 2))
;;; (irgb-green avecolor) = (floor (/ (+ (irgb-green color1) (irgb-green color2)) 2))
;;; (irgb-blue avecolor) = (floor (/ (+ (irgb-blue color1) (irgb-blue color2)) 2))
;;; Problem: What if the two components sum to a value greater than 255?
When we say "integer-encoded RGB color", what do we mean?
One of those strange numbers given back by (irgb _ _ _)
Why do we do this much work? It seems like more work to write the documentation than it does to write the code?
Forces us to think more carefully about our procedures.
What are the legal inputs? (What form can they take?)
What form does the output take? Useful for two weeks from now when we don't remember.
What might go wrong?
Etc.