Next: , Previous: , Up: Files and Ports   [Contents][Index]

4.6.2 Port Properties

Function: port-closed? port

Returns #t if port is closed.

Function: port-type obj

If obj is not a port returns false, otherwise returns a symbol describing the port type, for example string or pipe.

Function: port-filename port

Returns the filename port was opened with. If port is not open to a file the result is unspecified.

Function: file-position port
Function: file-position port #f

Returns the current position of the character in port which will next be read or written. If port is open to a non-file then #f is returned.

Function: file-position port k

Sets the current position in port which will next be read or written. If successful, #f is returned. If port is open to a non-file, then file-position returns #f.

Function: port-line port
Function: port-column port

If port is a tracked port, return the current line (column) number, otherwise return #f. Line and column numbers begin with 1. The column number applies to the next character to be read; if that character is a newline, then the column number will be one more than the length of the line.

Function: freshline port

Outputs a newline to optional argument port unless the current output column number of port is known to be zero, ie output will start at the beginning of a new line. port defaults to current-output-port. If port is not a tracked port freshline is equivalent to newline.

Function: isatty? port

Returns #t if port is input or output to a serial non-file device.

procedure: char-ready?
procedure: char-ready? port

Returns #t if a character is ready on the input port and returns #f otherwise. If char-ready? returns #t then the next read-char operation on the given port is guaranteed not to hang. If the port is at end of file then char-ready? returns #t. Port may be omitted, in which case it defaults to the value returned by current-input-port.

Rationale Char-ready? exists to make it possible for a program to accept characters from interactive ports without getting stuck waiting for input. Any input editors associated with such ports must ensure that characters whose existence has been asserted by char-ready? cannot be rubbed out. If char-ready? were to return #f at end of file, a port at end of file would be indistinguishable from an interactive port that has no ready characters.

procedure: wait-for-input x
procedure: wait-for-input x port1 …

Returns a list those ports port1 … which are char-ready?. If none of port1 … become char-ready? within the time interval of x seconds, then #f is returned. The port1 … arguments may be omitted, in which case they default to the list of the value returned by current-input-port.

Next: , Previous: , Up: Files and Ports   [Contents][Index]