Fundamentals of CS I (CS151 2002F)
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
Back to Program Input and Output. On to Pause for Breath.
Held Wednesday, November 6, 2002
Summary
Today we consider how to make Scheme read values and characters from files and write values to other files.
Related Pages
Notes
pause for breath.
(mapfuns list-of-funs val),
that builds a list of values by successively applying each function
in list-of-funs to val. For example,
> (mapfuns (list (left-section * 4) (right-section - 2)) 5)
(20 3)
Overview
anythingyou can do on the computer.
(open-input-file file-name).
(open-output-file file-name).
(read port)
(newline port)
(write value port)
(display value port)
(close-input-port port)
(close-output-port port)
(let* (; Prepare to read from a file
(source (open-input-file "data"))
; Read one value
(value (read source)))
; We're done, so clean up.
(close-input-port source)
; Return the value read
value)
read do when there's nothing left in the file?
It returns a special value (which DrScheme displays as
#<eof>).
eof-object?
(read-char port).
read procedure.
(peek-char port)
read-char encounters the end of the file, it returns
the same special value as read
Thursday, 29 August 2002 [Samuel A. Rebelsky]
Wednesday, 6 November 2002 [Samuel A. Rebelsky]
Back to Program Input and Output. On to Pause for Breath.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
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 Mon Dec 2 08:41:45 2002.
The source to the document was last modified on Wed Nov 6 08:24:27 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Outlines/outline.36.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby