Please send questions to st10@humboldt.edu .

; CIS 130 - Week 3, Wednesday, 02-03-10

(define MAX-SAFE-TEMP 120)
MAX-SAFE-TEMP

; (define (make-striped-box color1 color2)   ; first line of a function
;                                            ; definition is its HEADER
;   
;   ; the expression after the header is called the function's BODY
;   
;   (add-horiz-stripe color1 10
;                     (create-solid-fabric color2 100 100))
; )
; 
; (make-striped-box "green" "yellow")
; (make-striped-box "purple" "orange")


; color1 and color2 are the PARAMETERS of the function
;    make-striped-box;
; when I use make-striped-box, I need to give it two
;    ARGUMENT expressions, and the values of those expressions
;    become the values of those parameters for that call

; and now I can used a make-striped-box expression anywhere
;    I can use an image expression

; (image-height (make-striped-box "black" "yellow"))
; (add-print chili (make-striped-box "black" "white"))


; if I wanted to TEST make-striped-box, I could use
;    check-expect to compare the call's actual value to
;    the value I EXPECT it to be
; (it isn't a good test unless you think you know what
;    it should do!)

; have you noticed:
; ...when describing an operation/function, we have been
;    taking care to describe what it EXPECTS,
;    and what it PRODUCES?
; we'll ALWAYS do that, when designing a new function,
;    and we'll always need to know that when we want
;    to use some function;

; here is another simple function: to compute the area of
;    a rectangle

; (define (rect-area length width)
;   (* length width)
; )


; (rect-area 40 100)
; (rect-area 3 5)


; (check-expect (rect-area 3 5) 15)
; ;(check-expect (rect-area (/ 1 3) 2) 0.66667)   ; this test fails
; (check-within (rect-area (/ 1 3) 2) 0.66667 .001) ; this succeeds



; (check-expect (make-striped-box "pink" "green")
;               (add-horiz-stripe "pink" 10
;                                 (create-solid-fabric "green" 100 100)))


;(make-striped-box "green")

; not all functions are designed as easily as rect-area!

; to help us get started, we'll be using DESIGN RECIPES,
;    step-by-step approaches to designing functions

; we'll start with a simple version (for simple functions),
;    and add steps later on;

; STEP 1 - problem analysis and data definition
; STEP 2 - CONTRACT/PURPOSE/HEADER

; what is a contract?
; a special comment containing:
;    the NAME of the function to be written
;    the TYPES of expressions it EXPECTS, and
;    the TYPE of value it PRODUCES (returns)
; written as so:
; contract: funct-name: type type .. type -> type

; contract: make-striped-box: string string -> image

; contract: rect-area: number number -> number

; next: create the PURPOSE (or PURPOSE STATEMENT)
;    notice how the contract doesn't DESCRIBE those values
;    it expects and produces?
;    ...now, you ADD this description in the PURPOSE statement,
;       a comment that DESCRIBES what this function EXPECTS
;                      and what it PRODUCES (returns)

; for make-striped-box...
; purpose: expects two colors, and produces a box image
;          of size 100x100 pixels with stripes of width
;          10 pixels of those two colors

; for rect-area...
; purpose: expects a length and a width of some rectangle,
;          and produces the area of that rectangle

; now, write the HEADER...
; (and DrScheme permits you to put ... as a "placeholder"
;    for the function body, until you're ready to write it)

; (define (make-striped-box color1 color2)
;   ...
; )


; STEP 3 - develop SPECIFIC EXAMPLES, written as check-*
;    expressions, for each "kind" of data/situation this
;    function can handle

(check-expect (make-striped-box "pink" "green")
              (add-horiz-stripe "pink" 10
                                (create-solid-fabric "green" 100 100)))
(check-expect (make-striped-box "blue" "purple")
              (add-horiz-stripe "blue" 10
                                (create-solid-fabric "purple" 100 100)))

(check-expect (rect-area 3 5) 15)
(check-within (rect-area (/ 1 3) 2) 0.66667 .001) ; this succeeds

;STEP 4 - skipping for now -- (use a TEMPLATE if there one for
;   your situation

;STEP 5 - develop/complete the function's body
;   (using what you've learned from writing the specific
;   examples)

(define (rect-area length width)
  (* length width)
)
  
(define (make-striped-box color1 color2)
  (add-horiz-stripe color1 10
                    (create-solid-fabric color2 100 100))
)

; STEP 6 - run the tests!