manpagez: man pages & more
info guile
Home | html | info | man
[ << ] [ < ] [ 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? obj

Returns #t if the argument is a port, and returns #f otherwise.

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 as open-bytevector-input-port and make-custom-binary-output-port.

However, Guile currently does not prevent use of textual I/O procedures such as display or read-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 of set-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 the SEEK_CUR argument (see section Random Access).

Scheme Procedure: port-has-port-position? port

Return #t is port supports port-position.

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 the SEEK_SET argument (see section Random Access).

Scheme Procedure: port-has-set-port-position!? port

Return #t is port supports set-port-position!.

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.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.