put-string, write-string - write a string to a textual output port
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
(import (scheme base)) ;R7RS
; R6RS only:
(put-string textual-output-port string)
(put-string textual-output-port string start)
(put-string textual-output-port string start count)
; R7RS only:
(write-string string)
(write-string string textual-output-port)
(write-string string textual-output-port start)
(write-string string textual-output-port start end)
Writes the characters of string starting at index start to
textual-output-port.
- R6RS
- Exactly count characters are written, defaulting to
(string-length string)
− start.
- R7RS
- The characters from start to end are written, with
end defaulting to (string-length
string ).
The start argument defaults to 0.
- R6RS
- Returns unspecified values.
- R7RS
- Returns an unspecified value.
(write-string "Hello, world!\n")
This procedure is used, instead of a generic procedure like
display(scheme), because it is slightly faster and makes it possible to
write only part of the string.
The R7RS variant specifies end instead of count to be consistent
with other procedures.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain. In particular, start and count must be non-negative
exact integer objects, and string must have a length of at least
start + count.
- &i/o-encoding (R6RS)
- The port's transcoder is in raise mode and it encountered a character that
could not be translated into bytes. The untranslated character can be
retrieved from the condition.
- &i/o-write (R6RS)
- There was an I/O error during the write operation.
- &i/o-port (R6RS)
- If this is included as part of an I/O condition then the port related to
the I/O error can be retrieved with i/o-error-port(3scm).
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
put-char(3scm), display(3scm), open-file-output-port(3scm)
The put-string procedure was introduced in R6RS as part of the reworked
I/O design. The write-string procedure is new in R7RS.