CSC151 2010S, Class 23: Conditionals Overview: * The parts of an algorithm, revisited. * Reading Q&A. * Lab. Admin: * Reading for Friday: Building Data Structures with Heterogeneous Lists. * Warning! This is a bit longer than normal. * Due: Assignment 5. * Assigned: Assignment 6. * EC for Thursday's CS Extra: StatsGames. 4:30 in 3821, snacks at 4:15 in CS commons * EC for Friday's CS Table: Alumni Conversations. * Noon JRC * EC for movie on polio vaccine, 7:30 Thursday south lounge * Unicef benefit Quiz * N key components of an algorithm * Conditionals * Input and output * Subroutines/Procedures * Which have their own input and output, which we call parameters * Loops and Repetition * Named values * Predetermined types and commands to work with those types * Bad jokes Questions on the reading * Ways to make choices (if TEST CONSEQUENT ALTERNATE) * (when TEST CONSEQUENT) * (cond (TEST CONSEQUENT) (TEST CONSEQUENT) (TEST CONSEQUENT) ... (else ALTERNATE)) The tests usually look like (whatever? params) (and TEST TEST) (or TEST TEST) (not TEST) E.g., (and (integer? x) (odd? x) (<= 0 x 100) (= 0 (x mod 7))) (define asa? (lambda (x) (and (integer? x) (odd? x) (<= 0 x 100)) (cond ((asa? x) ...) Reflection (define rgb-brighter? (lambda (rgb1 rgb2) (if (> (rgb-brightness rgb1) (rgb-brightness rgb2)) #t #f))) vs. (define rgb-brighter? (lambda (rgb1 rgb2) (> (rgb-brightness rgb1) (rgb-brightness rgb2)))) (= 0 (x mod 7)))