Functions Design Recipe
1. Write down a signature, a purpose statement, and a function header.
A signature is a comment that tells the readers of your design how many inputs your function consumes, from what collection of data they are drawn, and what kind of output data it produces.
A purpose statement is a comment that summarizes the purpose of the function in a single line. If you are ever in doubt about a purpose statement, write down the shortest possible answer to the question “what does the function compute?”
2. Illustrate the signature and the purpose statement with some tests. To construct a test, pick one piece of data from each input class from the signature and determine what you expect back. Use a check-expect function.
3. Formulate how the function computes its results – develop a Scheme expression that uses Scheme’s primitive operations, other functions, and the variables.
Example
(define (area-of-disk r) (* 3.14 (* r r))) ;; Signature: area-of-ring : number number -> number ;; Purpose: to compute the area of a ring whose radius is ;; outer and whose hole has a radius of inner ;; Tests: (check-expect (area-of-ring 5 3) 50.24) ;; Definition: (define (area-of-ring outer inner) (- (area-of-disk outer) (area-of-disk inner)))




