CSC151 2009F, Class 52: Objects, Continued Admin: * Attendance is EXPECTED next week. Double penalties for missing class (unless excused). * As you requested, there will be no quiz today. * Reading for Monday: Files. * EC for: * Latin-American Ensemble Performance on Saturday 7:30 in SL * Community Choir, Friday, 7:30, Herrick * Dance Troupe Performances this week, lots of times and places * 4:15 today in Steiner * 5:30 on Saturday somewhere in Noyce * Tuesday evening at community meal * And more! * Friday at 4:15 recitals in SL or Bucksbaum 102 or ... * Womens Basketball 5pm today * There was a troubling alcohol-related incident on campus earlier this week. * Please behave responsibly before, during, and after Waltz. * Are there questions on the exam? Overview: * Exam stuff. * Summary of objects in Scheme. * Questions on objects in Scheme. * Lab. Exam Stuff * Do we have to explain our tests in the unit test problem? * No, but it would be nice * In vector-reverse!, what do you mean when you say "Don't use 'reverse'"? * You can't solve it with (list->vector (reverse (vector->list vec))) * Of course, that also doesn't change the original vector * What does string-vector-index-of-largest do? * Finds the largest string in a subvector * Returns the index of that string Objects in Scheme * An object is: A named thing * Objects have an internal state * Objects respond to messages * And the only way you can access their internal information is through those messages * In Scheme, we implement objects as functions, often with code like (define object (lambda (message) (cond ((equal? message ':do-this!) ...) ((equal? message ':do-that!) ...) * In Scheme, we use let to define the internal state (define object (let ((state (vector whatever))) (lambda (message) ...))) * In Scheme, when creating multiple objects, we use an "interesting" nesting of lambdas and lets (define make-object (lambda () (let ((state (vector whatever))) (lambda (message) ...)))) Back to the exam * How do I swap the elements in a vector at positions x and y * This won't work (vector-set! vec x (vector-ref vec y)) (vector-set! vec y (vector-ref vec x)) * Why not? Think about it. * So, we need to remember the values (let ((valx (vector-ref vec x)) (valy (vector-ref vec y))) ...) * Can you give me a hint as to how to write lookup-in-dictionary using binary-search (define lookup-in-dictionary (lambda (word dictionary) (let ((result (binary-search _____))) ...))) Questions? Lab