GNU Info

Info Node: (guile.info)String Ports

(guile.info)String Ports


Next: Soft Ports Prev: File Ports Up: Port Types
Enter node , (file) or (file)node

String Ports
------------

The following allow string ports to be opened by analogy to R4R* file
port facilities:

 - primitive: call-with-output-string proc
     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.

 - primitive: call-with-input-string str proc
     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.

 - procedure: with-output-to-string thunk
     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.

 - procedure: with-input-from-string string thunk
     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.

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.

At present there isn't a procedure that simply returns a new string
port.  There's also no way of opening read/write string ports from
Scheme even though it's possible from C.  SRFI 6 could be implemented
without much difficulty.


automatically generated by info2www version 1.2.2.9