mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-10 03:10:25 +02:00
* 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.
This commit is contained in:
parent
1669305496
commit
e3d8af60c4
2 changed files with 69 additions and 2 deletions
|
@ -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))))
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue