CSC153, Class 27: Input and Output in Scheme WE'LL START A FEW MINUTES LATE SO THAT THE 151 STUDENTS HAVE TIME TO FINISH THEIR EXAM! Overview: * Review: Output in Scheme * Input in Scheme * Lab Notes: * Read Files in Scheme * Questions on writeup 3? * Questions on yesterday's class? * Questions on Exam 2? + Plus short discussion. + Problem one: Currying + Problem two: Recurrences Minimum bound: Five different recurrences + Problem three: Weird procedure for quicksort. Understand the procedure. Document the procedure. Use the procedure to implement vector-based quicksort. + Problem four: String to value "\"Hello\"" + Problem five: Elegance Mantras Questions on writeup 3: Q Why does sequential-search only take a list and a predicate? What about the value you're searching for? A You're searching for the first value that matches the *unary* predicate (search odd? lst) (search (left-section = 5) lst) ---------------------------------------- Review: Output procedures in Scheme * Display: Displays its parameter * Print: Prints its parameter * How do they differ? + Print requires an output port (no) + Print permits an output port (yes) But so does display + Print adds the newline (no) Neither does display + Display processes escaped characters (yes) * Differ primarily in treatment of strings. + print prints strings as Scheme values. + display prints strings as humans would expect to read them (w/o quotes, with escaped characters processed) * Error: Prints its parameters + More parameters + In DrScheme, prints pretty Bug and the text is in red. + Error stops your program * write, which seems to be the same as print * (newline), which prints a newline character Key input procedures: * read (converse of write/print): Read a Scheme value. * read-char * peek-char In their base form, none of these take any parameters. LAB ---------------------------------------- Reflection: * What's the difference between typing 'a and a in response to a read prompt? * Explain > (read) ; Type in OGE oge > (read) ; Type in (list 1 2 3) (list 1 2 3) * How can I enter a procedure? > (define foo (read)) ; Type in (lambda (x) (+ x 1)) > foo (lambda (x) (+ x 1)) > (eval foo) # > ((eval foo) 3) 4 * How can I prompt for, read, and return a sequence of values? (define prompt-and-read (lambda (prompt) (display prompt) (display " ") (read))) (list (prompt-and-read "A:") (prompt-and-read "B:") (prompt-and-read "C:"))