lecture5

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

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 2/19/10 Class 5: Constructi ng Procedure s David Evans cs1120 Fall 2009
Background image of page 1

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

View Full DocumentRight Arrow Icon
2/19/10 Menu Problem Set 1 Evaluation Constructing Procedures Returning Problem Sets Procedure Return Problem Set 1 at end of class today 22
Background image of page 2
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 This means every non-false value is considered “true”. 33
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
2/19/10 55
Background image of page 5

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

View Full DocumentRight Arrow Icon
2/19/10 Defining not not not is a built-in procedure that takes one (define (not v) (if v #f #t)) 66
Background image of page 6
2/19/10 (if (not "cookies") "eat" "starve") (not "cookies") => #f So, value of the if expression is value of Expression 2 => “starve” 77
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
2/19/10 Iffy Proposition (if Expression #t #f) == Expression Is this always true? (if “cookies” #t #f) 1010
Background image of page 10
2/19/10 Brighter brighter? ? (define brighter?
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2010 for the course CS 150 taught by Professor Humphreys,g during the Fall '08 term at UVA.

Page1 / 31

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

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online