Kawa, the Java-based Scheme system

Node:Ports, Next:Format, Previous:Files, Up:Input-Output

### Ports

current-error-port | Function

Return the port to which errors and warnings should be sent (the standard error in Unix and C terminology).

read-line [port [handle-newline]] | Function

Reads a line of input from port. The handle-newline parameter determines what is done with terminating end-of-line delimiter. The default, `'trim`, ignores the delimiter; `'peek` leaves the delimiter in the input stream; `'concat` appends the delimiter to the returned value; and `'split` returns the delimiter as a second value. You can use the last three options to tell if the string was terminated by end-or-line or by end-of-file.

open-input-string string | Function

Takes a string and returns an input port that delivers characters from the string. The port can be closed by `close-input-port`, though its storage will be reclaimed by the garbage collector if it becomes inaccessible.
              (define p
                (open-input-string "(a . (b c . ())) 34"))

              (input-port? p)                 -->  #t
              (read p)                        -->  (a b c)
              (read p)                        -->  34
              (eof-object? (peek-char p))     -->  #t

open-output-string | Function

Returns an output port that will accumulate characters for retrieval by `get-output-string`. The port can be closed by the procedure `close-output-port`, though its storage will be reclaimed by the garbage collector if it becomes inaccessible.
              (let ((q (open-output-string))
                (x '(a b c)))
                  (write (car x) q)
                  (write (cdr x) q)
                  (get-output-string q))        -->  "a(b c)"

get-output-string output-port | Function

Given an output port created by `open-output-string`, returns a string consisting of the characters that have been output to the port so far.

call-with-input-string string proc | Function

Create an input port that gets its data from string, call proc with that port as its one argument, and return the result from the call of proc

call-with-output-string proc | Function

Create an output port that writes its data to a string, and call proc with that port as its one argument. Return a string consisting of the data written to the port.

force-output [port] | Function

Forces any pending output on port to be delivered to the output device and returns an unspecified value. If the port argument is omitted it defaults to the value returned by `(current-output-port)`.

An interactive input port has a prompt procedure associated with it. The prompt procedure is called before a new line is read. It is passed the port as an argument, and returns a string, which gets printed as a prompt.

input-port-prompter port | Function

Get the prompt procedure associated with port.

set-input-port-prompter! port prompter | Function

Set the prompt procedure associated with port to prompter, which must be a one-argument procedure taking an input port, and returning a string.

default-prompter port | Function

The default prompt procedure. It returns `"#|kawa:` L`|# "`, where L is the current line number of port. When reading a continuation line, the result is `"#|`C`---:`L`|# "`, where `C` is the character returned by `(input-port-read-state` port`)`. The prompt has the form of a comment to make it easier to cut-and-paste.

port-column input-port | Function
port-line input-port | Function

Return the current column number or line number of input-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.)

set-port-line! port line | Function

Set (0-origin) line number of the current line of port to num.

input-port-line-number port | Function

Get the line number of the current line of port, which must be a (non-binary) input port. The initial line is line 1. Deprecated; replaced by `(+ 1 (port-line` port`))`.

set-input-port-line-number! port num | Function

Set line number of the current line of port to num. Deprecated; replaced by `(set-port-line!` port`(-` num`1))`.

input-port-column-number port | Function

Get the column number of the current line of port, which must be a (non-binary) input port. The initial column is column 1. Deprecated; replaced by `(+ 1 (port-column` port`))`.

input-port-read-state port | Function

Returns a character indicating the current `read` state of the port. Returns `#\Return` if not current doing a read, `#\"` if reading a string; `#\|` if reading a comment; `#\(` if inside a list; and `#\Space` when otherwise in a `read`. The result is intended for use by prompt prcedures, and is not necessarily correct except when reading a new-line.

symbol-read-case | Variable

A symbol that controls how `read` handles letters when reading a symbol. If the first letter is `U`, then letters in symbols are upper-cased. If the first letter is `D` or `L`, then letters in symbols are down-cased. If the first letter is `I`, then the case of letters in symbols is inverted. Otherwise (the default), the letter is not changed. (Letters following a `\` are always unchanged.)

port-char-encoding | Variable

Controls how bytes in external files are converted to/from internal Unicode characters. Can be either a symbol or a boolean. If `port-char-encoding` is `#f`, the file is assumed to be a binary file and no conversion is done. Otherwise, the file is a text file. The default is `#t`, which uses a locale-dependent conversion. If `port-char-encoding` is a symbol, it must be the name of a character encoding known to Java. For all text files (that is if `port-char-encoding` is not `#f`), on input a `#\Return` character or a `#\Return` followed by `#\Newline` are converted into plain `#\Newline`. This variable is checked when the file is opened; not when actually reading or writing. Here is an example of how you can safely change the encoding temporarily:
              (define (open-binary-input-file name)
                (fluid-let ((port-char-encoding #f)) (open-input-file name)))