Computer Science Fundamentals (CS153 2003S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Contents:
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.
The file /home/rebelsky/Web/Courses/CS153/2003S/Examples/numbers
contains five hundred and twenty-eight natural numbers. What is their
sum?
Note: That file was copied from a similar file produced by Mr. Stone.
Using 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
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 sum-of-file
or file-size
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.
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.
Use the 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]
http://www.math.grin.edu/~stone/courses/scheme/files.xhtml
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/files.html
Sunday, 4 March 2001 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/files.html
Wednesday, 6 November 2002 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/files.html
Friday, 7 March 2003 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/files.html
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Disclaimer:
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 May 6 09:19:48 2003.
The source to the document was last modified on Fri Mar 7 10:21:26 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/files.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby