Node:String Ports,
Next:Soft Ports,
Previous:File Ports,
Up:Port Types
27.9.2 String Ports
The following allow string ports to be opened by analogy to R4R*
file port facilities:
call-with-output-string proc
|
Scheme Procedure |
scm_call_with_output_string (proc)
|
C Function |
Calls the one-argument procedure proc with a newly created output
port. When the function returns, the string composed of the characters
written into the port is returned.
|
call-with-input-string string proc
|
Scheme Procedure |
scm_call_with_input_string (string, proc)
|
C Function |
Calls the one-argument procedure proc with a newly
created input port from which string's contents may be
read. The value yielded by the proc is returned.
|
with-output-to-string thunk
|
Scheme Procedure |
Calls the zero-argument procedure thunk with the current output
port set temporarily to a new string port. It returns a string
composed of the characters written to the current output.
|
with-input-from-string string thunk
|
Scheme Procedure |
Calls the zero-argument procedure thunk with the current input
port set temporarily to a string port opened on the specified
string. The value yielded by thunk is returned.
|
open-input-string str
|
Scheme Procedure |
scm_open_input_string (str)
|
C Function |
Take a string and return an input port that delivers characters
from the string. The port can be closed by
close-input-port , though its storage will be reclaimed
by the garbage collector if it becomes inaccessible.
|
open-output-string
|
Scheme Procedure |
scm_open_output_string ()
|
C Function |
Return an output port that will accumulate characters for
retrieval by get-output-string . The port can be closed
by the procedure close-output-port , though its storage
will be reclaimed by the garbage collector if it becomes
inaccessible.
|
get-output-string port
|
Scheme Procedure |
scm_get_output_string (port)
|
C Function |
Given an output port created by open-output-string ,
return a string consisting of the characters that have been
output to the port so far.
|
A string port can be used in many procedures which accept a port
but which are not dependent on implementation details of fports.
E.g., seeking and truncating will work on a string port,
but trying to extract the file descriptor number will fail.