CSC151.01 2006S, Class 17: Recursion with Files Admin: * Reading for Monday: Preconditions and Postconditions * Due: HW7. * Distributed: Exam 1 (due next Friday). * Sorry about the confusion on Wednesday's lab. * EC * No Tuesday Extra next week. * Is anyone participating in local events this weekend and wants classmate support? * Vince opens for some random band (a Dead Ship) on Saturday Bobs. About 9:00 p.m. * Sam available today 10:00-12:45, 2:15-3:05. * Sam gone until Sunday. Prof. Davis substitutes via email. Overview: * About the exam * About files. * Key file operations. * File recursion. * Lab. /About the Exam/ * See the exam for details. * What readings? * Everything up to and including Files /File Operations/ * (read INPUT_PORT) - reads first thing from the source * (peek-char INPUT_PORT) - peeks at, but does not read, the next character in the source * (read-char INPUT_PORT) - reads the next character * (open-input-file STRING-THAT-NAMES-THE-FILE) - gives you back something you can apply read and peek-char to (define source (open-input-file STRING-THAT-NAMES-THE-FILE)) (proc (open-input-file STRING-THAT)) (define proc (lambda (source) * (close-input-port INPUT-PORT) - we're done with the file * (eof-object? VALUE) - true or false, depending on whether or not its the end of file object (define eof? (lambda (input-port) (eof-object? (peek-char input-port)))) * Lots of stuff for writing, which we'll ignore right now Pattern of recursion (define rec-proc (lambda (values) (if (simple-enough-to-do-the-base-case values) (base-case) (recurse on a simpler case)))) (define rec-file-proc (lambda (input-port other-values) (if (eof? input-port) (close-and-return input-port (base-case)) (combine (read input-port) (rec-file-proc input-port other-values))))) (define close-and-return (lambda (input-port return-value) (close-input-port input-port) return-value))