CSC151 2007S, Class 10: Representing Images as Lists of Spots Admin: * Assignment 3 due! * PLEASE USE THE CORRECT TITLE! * Reminder: Quiz 2 on Friday (some code reading, some code writing). * Reminder: Exam 1 distributed on Friday. * Reminder: Purcell convocation tomorrow. * Reading for Friday: Documenting Procedures. * Some stuff from yesterday * So, is Grinnell too classist in its reaction to the snow? Overview: * Stuff from Yesterday * Lists in Scheme. * Basic list operations. * Spot lists: Another perspective on images. ==Stuff from Yesterday== * So, how do we write grade-count? ;;; Procedure ;;; grade-count ;;; Purpose ;;; To decide what extra "count" to give for a grade, using ;;; the policy "80 and above counts as 1"; anything else counts ;;; as 0. ;;; Produces: ;;; count, an integer (either 0 or 1) ;;; Strategy: ;;; divide the raw score by 100 ;;; 0..79 => .0.. .79 ;;; 80..100 => .80 .. 1.00 ;;; Add .2 ;;; 0..79 => .2.. .99 ;;; 80..100 => 1.00 .. 1.20 ;;; Truncate! ;;; 0..79 => 0 .. 0 ;;; 80..100 => 1 .. 1 ;;; Alternate strategy: Divide by 80 and use the floor ;;; ALternate strategy from other 151 ;;; (modulo (bound grade 79 80) 79) (define bound (lambda (val lower upper) (min (max val lower) upper))) (define grade-count1 (lambda (grade) (truncate (+ 0.2 (/ grade 100))))) (define grade-count2 (lambda (grade) (truncate (/ grade 80)))) (define grade-count3 (lambda (grade) (modulo (bound grade 79 80) 79))) Which is better? * divide by 100, add .20, truncate because it "feels better" * bound and mod, because it's more straightfoward and has fewer operations * grade-count2 is easier to understand/it's more intuitive * grade-count3 might be easier to change * grade-count2 and grade-count1 would be easier for other values * grade-count3 requires the prior definition of "bound" ===Other ways to look at modulo=== Drawings on the real white board. TONS OF EXTRA CREDIT IF YOU WRITE A PROGRAM TO REPLICATE THOSE DRAWINGS I JUST MADE ==Lists in Scheme== * Innovation: Lists as a built-in type * Wonderful idea: Easy to build collections from lists ==Basic list operations== * BUild lists like you build drawings * Start with a simple list: The empty list * Create new lists by adding to that list * ONLY AT THE FRONT ==Spot lists: Another perspective on images==