Scan through this lab to determine what kinds of tasks you'll need to complete.
Read the reading on files in Scheme.
The file /home/stone/courses/scheme/examples/numbers contains five hundred and twenty-eight natural numbers. What is their sum?
sum-of-file as a pattern, write a Scheme procedure
file-size that takes as argument a string that names a file
and returns the number of characters in that file (that is, the number of
read-char can be called to read a character from
the file without returning the end-of-file object).
Find out what happens if
is given a string that does not name any existing file.
Write a procedure,
read-lines, that takes the name of a
file as a parameter and returns a list of all the lines of the file
(with each line represented as a string).
Write a procedure,
display-file, that takes the name of
a file as a parameter and displays the contents of the file with each
line preceded by its line number.
store-divisors procedure to draw up a list of the
divisors of 120, storing them in a file named divisors-of-120. Examine the
file afterwards and confirm that the answer is correct. (Don't give this
procedure an extremely large number as argument -- it's too slow. There
are more efficient ways to find divisors!)
The Scheme standard says that if you try to open an output port to a file that already exists, ``the effect is unspecified,'' i.e., anything might happen.
a. Find out through experimentation what DrScheme does in this situation.
b. Find out using DrScheme's Help Desk what DrScheme allows programmers to do in this situation. (The help desk document is entitled Opening file ports.)
Write a Scheme procedure that takes as arguments two file names (an input file and an output file), counts the number of occurences of each vowel in the input file, and writes ther esult to the output file.
If you have time or inclination, extend your procedure to deal with all 127 ASCII characters.
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/files.html
Source text last modified Mon Nov 6 10:45:26 2000.
This page generated on Mon Nov 6 10:49:58 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at email@example.com