mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-19 02:00:26 +02:00
call-with-{input,output}-string implemented in scheme
* module/ice-9/boot-9.scm (call-with-input-string) (call-with-output-string): Implement in Scheme. * libguile/strports.c (scm_call_with_output_string): (scm_call_with_input_string): Dispatch to Scheme.
This commit is contained in:
parent
4df9e5eb0f
commit
a62b5c3d54
2 changed files with 28 additions and 22 deletions
|
@ -1456,6 +1456,12 @@ procedures, their behavior is implementation dependent."
|
|||
(call-with-output-file file
|
||||
(lambda (p) (with-error-to-port p thunk))))
|
||||
|
||||
(define (call-with-input-string string proc)
|
||||
"Calls the one-argument procedure @var{proc} with a newly created
|
||||
input port from which @var{string}'s contents may be read. The value
|
||||
yielded by the @var{proc} is returned."
|
||||
(proc (open-input-string string)))
|
||||
|
||||
(define (with-input-from-string string thunk)
|
||||
"THUNK must be a procedure of no arguments.
|
||||
The test of STRING is opened for
|
||||
|
@ -1468,6 +1474,14 @@ procedures, their behavior is implementation dependent."
|
|||
(call-with-input-string string
|
||||
(lambda (p) (with-input-from-port p thunk))))
|
||||
|
||||
(define (call-with-output-string proc)
|
||||
"Calls the one-argument procedure @var{proc} with a newly created output
|
||||
port. When the function returns, the string composed of the characters
|
||||
written into the port is returned."
|
||||
(let ((port (open-output-string)))
|
||||
(proc port)
|
||||
(get-output-string port)))
|
||||
|
||||
(define (with-output-to-string thunk)
|
||||
"Calls THUNK and returns its output as a string."
|
||||
(call-with-output-string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue