Summary: In this laboratory, we explore file creation, input, and output in Scheme.
a. Scan through this lab to determine what kinds of tasks you'll need to complete.
b. You should also scan through the reading on files in Scheme.
c. Start DrScheme.
contains five hundred and twenty-eight natural numbers.
sum-of-file from the reading to determine their sum.
b. How would you quickly determine if your attempt to sum those numbers was correct?
Note: That file was copied from a similar file produced by Mr. Stone.
sum-of-file as a pattern, write a Scheme
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 times that
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). You can certainly use the
read-line procedure from the reading as a helper for
sum-of-file as a pattern for
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. You may find it useful to call
upon the previous procedure to do the reading.
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. Hence, designers of a particular implementation of Scheme
are free to do what they choose.
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 the result to the output file.
If you have time or inclination, extend your procedure to deal with all 127 ASCII characters.
Fall 2000 [Samuel A. Rebelsky]
Sunday, 4 March 2001 [Samuel A. Rebelsky]
Wednesday, 6 November 2002 [Samuel A. Rebelsky]
Friday, 7 March 2003 [Samuel A. Rebelsky]
Sunday, 6 April 2003 [Samuel A. Rebelsky]
Tuesday, 8 April 2003 [Samuel A. Rebelsky]
read-linesproblem to make it clear that
read-lineis a helper, rather than a pattern.
Thursday, 30 October 2003 [Samuel A. Rebelsky]
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue Dec 9 13:59:02 2003.
The source to the document was last modified on Thu Oct 30 12:51:45 2003.
This document may be found at