[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.14.10.6 Port Manipulation
The procedures listed below operate on any kind of R6RS I/O port.
- Scheme Procedure: port-transcoder port
Returns the transcoder associated with port if port is textual and has an associated transcoder, and returns
#f
if port is binary or does not have an associated transcoder.
- Scheme Procedure: binary-port? port
Return
#t
if port is a binary port, suitable for binary data input/output.Note that internally Guile does not differentiate between binary and textual ports, unlike the R6RS. Thus, this procedure returns true when port does not have an associated encoding—i.e., when
(port-encoding port)
is#f
(see section port-encoding). This is the case for ports returned by R6RS procedures such asopen-bytevector-input-port
andmake-custom-binary-output-port
.However, Guile currently does not prevent use of textual I/O procedures such as
display
orread-char
with binary ports. Doing so “upgrades” the port from binary to textual, under the ISO-8859-1 encoding. Likewise, Guile does not prevent use ofset-port-encoding!
on a binary port, which also turns it into a “textual” port.
- Scheme Procedure: textual-port? port
Always return
#t
, as all ports can be used for textual I/O in Guile.
- Scheme Procedure: transcoded-port binary-port transcoder
The
transcoded-port
procedure returns a new textual port with the specified transcoder. Otherwise the new textual port’s state is largely the same as that of binary-port. If binary-port is an input port, the new textual port will be an input port and will transcode the bytes that have not yet been read from binary-port. If binary-port is an output port, the new textual port will be an output port and will transcode output characters into bytes that are written to the byte sink represented by binary-port.As a side effect, however,
transcoded-port
closes binary-port in a special way that allows the new textual port to continue to use the byte source or sink represented by binary-port, even though binary-port itself is closed and cannot be used by the input and output operations described in this chapter.
- Scheme Procedure: port-position port
If port supports it (see below), return the offset (an integer) indicating where the next octet will be read from/written to in port. If port does not support this operation, an error condition is raised.
This is similar to Guile’s
seek
procedure with theSEEK_CUR
argument (see section Random Access).
- Scheme Procedure: set-port-position! port offset
If port supports it (see below), set the position where the next octet will be read from/written to port to offset (an integer). If port does not support this operation, an error condition is raised.
This is similar to Guile’s
seek
procedure with theSEEK_SET
argument (see section Random Access).
- Scheme Procedure: call-with-port port proc
Call proc, passing it port and closing port upon exit of proc. Return the return values of proc.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.