{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture5

# lecture5 - Click to edit Master subtitle style Class 5...

This preview shows pages 1–11. Sign up to view the full content.

Click to edit Master subtitle style 2/19/10 Class 5: Constructi ng Procedure s David Evans cs1120 Fall 2009

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/19/10 Menu Problem Set 1 Evaluation Constructing Procedures Returning Problem Sets Procedure Return Problem Set 1 at end of class today 22
2/19/10 From Question 1/2: (if (not "cookies") "eat" "starve") Evaluation Rule 5: If. To evaluate an if expression: (a) Evaluate the predicate expression (b) If it evaluates to false , the value of the if expression is the value of the alternate expression. Otherwise, the value of the if expression is the value of consequent expression. This means every non-false value is considered “true”. 33

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/19/10 Evaluate (not "cookies") Evaluation Rule 3. Application. a. Evaluate all the subexpressions <primitive:not> “cookies” The quotes really matter here! Without them what would cookies evaluate to? b. Apply the value of the first subexpression How do we evaluate an application of a primitive if we don’t know its pre-defined meaning? 44
2/19/10 55

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/19/10 Defining not not : Value ° Boolean not is a built-in procedure that takes one input value and outputs a Boolean. (define (not v) (if v #f #t)) 66
2/19/10 (if (not "cookies") "eat" "starve") (not "cookies") => #f So, value of the if expression is value of Expression 2 => “starve” 77

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/19/10 brighter? (define brighter? (lambda (color1 color2) (if (> (+ (get-red color1) (get-green color1) (get-blue color1) ) (+ (get-red color2) (get- green color2) (get-blue color2)) #t #f))) Is this correct? Maybe...but very hard to tell. Your code should appear in a way that reveals its structure 88
2/19/10 (define brighter? (lambda (color1 color2) (if (> (+ (get-red color1) (get-green color1) (get-blue color1)) (+ (get-red color2) (get-green color2) (get-blue color2)) #t #f))) Use [Tab] in DrScheme to line up your code structurally! 99

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/19/10 Iffy Proposition (if Expression #t #f) == Expression Is this always true?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}