CSC151.02, Class 23: Review of Exam 1 Admin: * Fruit juice (plus blue stuff) * Are there questions on the homework? * I've flipped the schedule around once again. * Two cool talks (both for extra credit) * Thursday, noon, Science 2413, Shaka McGlotten '97, "A Conversation on Gendered, Racial, and Sexual Dynamics of Online Spaces". * Friday, noon, Science 2413, Joshua Shaw Vickery '02, "Real-World Java Programming". Overview: * General issues * Problem 1 * Problem 2 * Problem 3 * Problem 4 * Problem 5 * Problem 6 /Problem 1: Types/ * Quiz! * Name * List all the types you know in Scheme. (Don't bother with the variants of number) * Count the number of types you wrote * list, number, character, symbol, string, boolean, procedure * null-list, exact-number, inexact-number (define type-of (lambda (val) (cond ((list? val) 'list) ((number? val) 'number) ((character? val) 'character) ... (else 'unknown) ))) /General Issues/ * I do not report averages, means, media, max, min, ... * I do not usually permit redos * I will discuss and argue grading * I pay attention to stupid anal-retentive stylistic issues * Format of six P's ;;; Procedure whatever. Purpose to do something, but ;;; I'm not sure what. Parameters * Choice of where to break lines (if (some-test) (string-append "a" "b") "Hello") * Returning #t and #f explicitly (if test #t #f) /Problem 2: Extending Sentences/ * "Compare the last character in the string to ..." (define extend (lambda (sentence) (cond ((equal? (string-ref str (- (string-length str) 1)) #\.) (string-append (substring str 0 (- (string-length str) 1)) ", I think.")) (... #\?) (... #\!)))) * Moral one: Work with the type as is, don't convert to another type. * Moral two: Preconditions are your friends. /Problem 3: singleton?/ (define singleton? (lambda (lst) (and (not (null? lst)) (null? (cdr lst))))) (define singleton? (lambda (lst) (if (null? lst) #f (if (and (not (null? lst)) (null? (cdr lst))) #t (if (and (not (null? lst))) (not (null? (cdr lst))) #f))))) /Problem 4: Close Numbers/ * What does it mean to be close? * Within 1% of each other. * Not a great metric, but you're stuck with it. * What are some potentially problematic inputs? (Inputs that are correct, but hard to process.) * Negative numbers * Zero * Repeated numbers * Very large * Very small * Exact vs. inexact * Some strategies used. /Problem 5: Choosing an Element/ /Problem 6/ (if test0 (if test1 #f (if test2 (if test3 #t test4) (if test5 #f test7))) (if #f test8 test9)) (if test0 (and (not test1) (if test2 (or test3 test4) (and (not test5) test7)) test9) (if test5 #f test7) => (and (not test5) test7) Try some examples. Suppose both hold. Suppose test5 doesn't hold. Note: Two different ways of thinking about the tests * The "if" way: Do this test, then this test, then this test. * The "defined" way: This holds when this combination holds Feel free to leave when you want. Feel free to come up and ask me questions.