Section 4.2: Functions that Test Conditions (continued)
Another Boolean-valued function ;Purpose ;To determine if someone is between 18 and 25. ;Contract ;18-to-25? : number -> boolean “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true
Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) … age …)) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true
Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) … (>= age 18) … (<= age 25) …) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true
Another Boolean-valued function ; 18-to-25? : number -> boolean (define (18-to-25? age) (and (>= age 18) (<= age 25))) “Examples of 18-to-25?:” (18-to-25? 17) “should be” false (18-to-25? 48) “should be” false (18-to-25? 21) “should be” true (18-to-25? 18) “should be” true (18-to-25? 25) “should be” true
Next time… Writing Conditional Functions