www.delorie.com/gnu/docs/guile/guile_309.html   search  
 
Buy GNU books!


Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2 Reading

[Generic procedures for reading from ports.]

Scheme Procedure: eof-object? x
C Function: scm_eof_object_p (x)
Return #t if x is an end-of-file object; otherwise return #f.

Scheme Procedure: char-ready? [port]
C Function: scm_char_ready_p (port)
Return #t if a character is ready on input port and return #f otherwise. If char-ready? returns #t then the next read-char operation on port is guaranteed not to hang. If port is a file port at end of file then char-ready? returns #t. (11)

Scheme Procedure: read-char [port]
C Function: scm_read_char (port)
Return the next character available from port, updating port to point to the following character. If no more characters are available, the end-of-file object is returned.

Scheme Procedure: peek-char [port]
C Function: scm_peek_char (port)
Return the next character available from port, without updating port to point to the following character. If no more characters are available, the end-of-file object is returned.(12)

Scheme Procedure: unread-char cobj [port]
C Function: scm_unread_char (cobj, port)
Place char in port so that it will be read by the next read operation. If called multiple times, the unread characters will be read again in last-in first-out order. If port is not supplied, the current input port is used.

Scheme Procedure: unread-string str port
C Function: scm_unread_string (str, port)
Place the string str in port so that its characters will be read in subsequent read operations. If called multiple times, the unread characters will be read again in last-in first-out order. If port is not supplied, the current-input-port is used.

Scheme Procedure: drain-input port
C Function: scm_drain_input (port)
This procedure clears a port's input buffers, similar to the way that force-output clears the output buffer. The contents of the buffers are returned as a single string, e.g.,

 
(define p (open-input-file ...))
(drain-input p) => empty string, nothing buffered yet.
(unread-char (read-char p) p)
(drain-input p) => initial chars from p, up to the buffer size.

Draining the buffers may be useful for cleanly finishing buffered I/O so that the file descriptor can be used directly for further input.

Scheme Procedure: port-column port
Scheme Procedure: port-line port
C Function: scm_port_column (port)
C Function: scm_port_line (port)
Return the current column number or line number of port, using the current input port if none is specified. If the number is unknown, the result is #f. Otherwise, the result is a 0-origin integer - i.e. the first character of the first line is line 0, column 0. (However, when you display a file position, for example in an error message, we recommend you add 1 to get 1-origin integers. This is because lines and column numbers traditionally start with 1, and that is what non-programmers will find most natural.)

Scheme Procedure: set-port-column! port column
Scheme Procedure: set-port-line! port line
C Function: scm_set_port_column_x (port, column)
C Function: scm_set_port_line_x (port, line)
Set the current column or line number of port, using the current input port if none is specified.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003