Functional Problem Solving (CSC 151 2014F) : Reference

Files


Opening and Closing Files

(open-input-file filename)
Standard File Procedure. Open the specified file for reading. Returns an input port.
(open-output-file filename)
Standard File Procedure. Open the specified file for writing. Returns an output port.
(close-input-port input-port)
Standard File Procedure. Close an open input port. (It is an error to try to close something that is not an input port, or an input port that is already closed.)
(close-output-port output-port)
Standard File Procedure. Close an open output port. (It is an error to try to close something that is not an output port, or an output port that is already closed.)

Reading From Files

(read input-port)
Standard File Procedure. Read the next value available on the specified port. If no characters remain, returns the end-of-file object.
(read-char input-port)
Standard File Procedure. Read the next character available on the specified port. If no characters remain, returns the end-of-file object.
(peek-char input-port)
Standard File Procedure. Determine the next character available on the specified port. If no characters remain, returns the end-of-file object.

Writing To Files

(display value output-port)
Standard File Procedure. Print a human-readable representation of value on the specified port.
(write value output-port)
Standard File Procedure. Print the verbose representation of the specified value to the specified port.
(write-char ch output-port)
Standard File Procedure. Write the the given character to the specified port.
(newline output-port)
Standard File Procedure. Write a newline (carriage return) to the specified output port.

Predicates

(input-port? val)
Standard File Predicate. Determine if val is an open input port.
(output-port? val)
Standard File Predicate. Determine if val is an open output port.
(file-exists? filename)
Standard File Procedure. Determine whether a file with the given name exists.
(eof-object? val)
Standard File Procedure. Determine if val is something returned by read (or read-char or peek-char) to indicate the end of input.

Miscellaneous

(delete-file filename)
Common File Procedure. Delete the file specified by filename. If the file doesn't exist, reports an error.