From e3d8af60c44b754a5834ee1558a7b63cd54592c9 Mon Sep 17 00:00:00 2001 From: "Greg J. Badros" Date: Mon, 14 Feb 2000 02:04:14 +0000 Subject: [PATCH] * slib.scm: Rename software-type to slib:software-type and make it public. * r4rs.scm: Added documentation; largely cut and pasted from R4RS info pages. --- ice-9/r4rs.scm | 69 +++++++++++++++++++++++++++++++++++++++++++++++++- ice-9/slib.scm | 2 +- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/ice-9/r4rs.scm b/ice-9/r4rs.scm index e5db3d661..f4cd2c9e9 100644 --- a/ice-9/r4rs.scm +++ b/ice-9/r4rs.scm @@ -55,23 +55,53 @@ (define *null-device* "/dev/null") (define (open-input-file str) + "Takes a string naming an existing file and returns an input port +capable of delivering characters from the file. If the file +cannot be opened, an error is signalled." (open-file str OPEN_READ)) (define (open-output-file str) + "Takes a string naming an output file to be created and returns an +output port capable of writing characters to a new file by that +name. If the file cannot be opened, an error is signalled. If a +file with the given name already exists, the effect is unspecified." (open-file str OPEN_WRITE)) -(define (open-io-file str) (open-file str OPEN_BOTH)) +(define (open-io-file str) + "Open file with name STR for both input and output." + (open-file str OPEN_BOTH)) + (define close-input-port close-port) (define close-output-port close-port) (define close-io-port close-port) (define (call-with-input-file str proc) + "PROC should be a procedure of one argument, and STR should be a +string naming a file. The file must +already exist. These procedures call PROC +with one argument: the port obtained by opening the named file for +input or output. If the file cannot be opened, an error is +signalled. If the procedure returns, then the port is closed +automatically and the value yielded by the procedure is returned. +If the procedure does not return, then the port will not be closed +automatically unless it is possible to prove that the port will +never again be used for a read or write operation." (let* ((file (open-input-file str)) (ans (proc file))) (close-input-port file) ans)) (define (call-with-output-file str proc) + "PROC should be a procedure of one argument, and STR should be a +string naming a file. The behaviour is unspecified if the file +already exists. These procedures call PROC +with one argument: the port obtained by opening the named file for +input or output. If the file cannot be opened, an error is +signalled. If the procedure returns, then the port is closed +automatically and the value yielded by the procedure is returned. +If the procedure does not return, then the port will not be closed +automatically unless it is possible to prove that the port will +never again be used for a read or write operation." (let* ((file (open-output-file str)) (ans (proc file))) (close-output-port file) @@ -90,32 +120,69 @@ (dynamic-wind swaports thunk swaports))) (define (with-input-from-file file thunk) + "THUNK must be a procedure of no arguments, and FILE must be a +string naming a file. The file must already exist. The file is opened for +input, an input port connected to it is made +the default value returned by `current-input-port', +and the THUNK is called with no arguments. +When the THUNK returns, the port is closed and the previous +default is restored. Returns the value yielded by THUNK. If an +escape procedure is used to escape from the continuation of these +procedures, their behavior is implementation dependent." (let* ((nport (open-input-file file)) (ans (with-input-from-port nport thunk))) (close-port nport) ans)) (define (with-output-to-file file thunk) + "THUNK must be a procedure of no arguments, and FILE must be a +string naming a file. The effect is unspecified if the file already exists. +The file is opened for output, an output port connected to it is made +the default value returned by `current-output-port', +and the THUNK is called with no arguments. +When the THUNK returns, the port is closed and the previous +default is restored. Returns the value yielded by THUNK. If an +escape procedure is used to escape from the continuation of these +procedures, their behavior is implementation dependent." (let* ((nport (open-output-file file)) (ans (with-output-to-port nport thunk))) (close-port nport) ans)) (define (with-error-to-file file thunk) + "THUNK must be a procedure of no arguments, and FILE must be a +string naming a file. The effect is unspecified if the file already exists. +The file is opened for output, an output port connected to it is made +the default value returned by `current-error-port', +and the THUNK is called with no arguments. +When the THUNK returns, the port is closed and the previous +default is restored. Returns the value yielded by THUNK. If an +escape procedure is used to escape from the continuation of these +procedures, their behavior is implementation dependent." (let* ((nport (open-output-file file)) (ans (with-error-to-port nport thunk))) (close-port nport) ans)) (define (with-input-from-string string thunk) + "THUNK must be a procedure of no arguments. +The test of STRING is opened for +input, an input port connected to it is made, +and the THUNK is called with no arguments. +When the THUNK returns, the port is closed. +Returns the value yielded by THUNK. If an +escape procedure is used to escape from the continuation of these +procedures, their behavior is implementation dependent." (call-with-input-string string (lambda (p) (with-input-from-port p thunk)))) (define (with-output-to-string thunk) + "Calls THUNK and returns its output as a string." (call-with-output-string (lambda (p) (with-output-to-port p thunk)))) (define (with-error-to-string thunk) + "Calls THUNK and returns its error output as a string." (call-with-output-string (lambda (p) (with-error-to-port p thunk)))) diff --git a/ice-9/slib.scm b/ice-9/slib.scm index 44fbdf6e7..94bcb481c 100644 --- a/ice-9/slib.scm +++ b/ice-9/slib.scm @@ -212,7 +212,7 @@ '*sc-expander* '(define))) -(define (software-type) +(define-public (slib:software-type) "Return a symbol describing the current platform's operating system. This may be one of AIX, VMS, UNIX, COHERENT, WINDOWS, MS-DOS, OS/2, THINKC, AMIGA, ATARIST, MACH, or ACORN.