Return the port to which errors and warnings should be sent (the standard error in Unix and C terminology).
Function: read-line
[port
[handle-newline
]]
Reads a line of input from
port
. Thehandle-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.
Function: open-input-string
string
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
Returns an output port that will accumulate characters for retrieval by
get-output-string
. The port can be closed by the procedureclose-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)"
Function: get-output-string
output-port
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.
Function: call-with-input-string
string
proc
Create an input port that gets its data from
string
, callproc
with that port as its one argument, and return the result from the call ofproc
Function: call-with-output-string
proc
Create an output port that writes its data to a
string
, and callproc
with that port as its one argument. Return a string consisting of the data written to the port.
Forces any pending output on
port
to be delivered to the output device and returns an unspecified value. If theport
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.
Function: set-input-port-prompter!
port
prompter
Set the prompt procedure associated with
port
toprompter
, which must be a one-argument procedure taking an input port, and returning a string.
Function: default-prompter
port
The default prompt procedure. It returns
"#|kawa:
, whereL
|# "L
is the current line number ofport
. When reading a continuation line, the result is"#|
, whereC
---:L
|# "C
is the character returned by(input-port-read-state
. The prompt has the form of a comment to make it easier to cut-and-paste.port
)
Function: port-column
input-port
Function: port-line
input-port
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.)
Function: input-port-line-number
port
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
))
Function: set-input-port-line-number!
port
num
Set line number of the current line of
port
tonum
. Deprecated; replaced by(set-port-line!
.port
(-num
1))
Function: input-port-column-number
port
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
))
Function: input-port-read-state
port
Returns a character indicating the current
read
state of theport
. Returns#\Return
if not current doing aread
,#\"
if reading a string;#\|
if reading a comment;#\(
if inside a list; and#\Space
when otherwise in aread
. The result is intended for use by prompt prcedures, and is not necessarily correct except when reading a new-line.
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.)
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. Ifport-char-encoding
is a symbol, it must be the name of a character encoding known to Java. For all text files (that is ifport-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)))
The number base (radix) to use by default when printing rational numbers. Must be an integer between 2 and 36, and the default is of course 10. For example setting
*print-base*
to 16 produces hexadecimal output.
If true, prints an indicator of the radix used when printing rational numbers. If
*print-base*
is respectively 2, 8, or 16, then#b
,#o
or#x
is written before the number; otherwise#
is written, whereN
ris the base. An exception is when
N
*print-base*
is 10, in which case a period is written after the number, to match Common Lisp; this may be inappropriate for Scheme, so is likely to change.