diff options
author | Andy Wingo <wingo@pobox.com> | 2012-03-07 13:34:06 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-03-07 13:34:06 +0100 |
commit | a62b5c3d5431cf68d94af5397116ca38f7d15840 (patch) | |
tree | 42624e996ac2bf295d05a6636649fef518900c99 /module/ice-9/boot-9.scm | |
parent | 4df9e5eb0f2cbdcd36cb2a50214f79a16816accf (diff) | |
download | guile-a62b5c3d5431cf68d94af5397116ca38f7d15840.tar.gz |
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.
Diffstat (limited to 'module/ice-9/boot-9.scm')
-rw-r--r-- | module/ice-9/boot-9.scm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 8fbddd07e..1630461e1 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -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 |