CSC151 2007S, Class 37: File Basics Admin: * It's your final chance for in-class questions on the exam. * I'll do my best to be available via email tonight. * EC: Today's Thursday Extra on Scripting Video with Scheme (4:30, 3821). * Reading for tomorrow: Storing images Overview: * Exam questions. * Data persistence. * Basic file operations. * Lab. =Your Questions on the Exam= ==How do I approach problem 1?== * Step by step, experimentally plus code analysis * Break it into smaller problems * You only need give the six P's for r; short comments about purpose would be useful for c and s. ==How do I build the values for problem 3?== * Build with list (define a-red-disc (list "disc" color.red 85 95 70)) * Those interested in doing extra work might define a disc.new procedure (define disc.new (lambda (color col row radius) (list "disc" color colo row radius))) ==How do I compare strings?== * In particular, how do I ask something like "Is the first element of the list the string "disc"?" (string=? "disc" (car lst)) (equal? "disc" (car lst)) NOT (= "disc" (car lst)) ==What does it mean when I get "illegal function"?== Almost invariably, that you are using a non-procedure in the procedure position. (null lst) (null null)$a ((+ 2 3) 4)a How do I track these problems down? LOOK AT EVERY OPEN PAREN AND CONSIDER THE FOLLOWING THING ==Why do I get the dreaded "Error: Wrong number of parameters" message?== =My Question on the Exam= Solved =Files!= * Need a way for data to persist * It's reasonable for programmers, even novice programmers, to know how to create and read from files * Key ideas in Scheme: * Files are named by strings "sams-incredbily-important-but-misspelled-picture.img" * These file names may, but need not, include a full path name "/home/rebelsky/glimmer/samples/junk.txt" * If you don't give the full name, it assumes the file is in your home directory (if you're lucky) * But you don't work directly with files, instead, you work with "ports" * File + Position * (open-input-file "filename") * (open-output-file "filename") * Need to be named * Need to be closed * (close-input-port port) * (close-output-port port)