Skip to content
Jan Špaček edited this page Apr 14, 2016 · 1 revision

This module provides a basic IO library for reading and writing bytes from files and the standard IO streams.

  • IO streams are handles to opened files
    • (io? io) returns true if io is an IO stream.
    • (io-eof? io) returns true if the stream io reached end of file.
    • (io-error? io) returns true if there was an error reading from or writing to io.
  • Standard IO streams
    • (io-stdin) returns the standard input stream.
    • (io-stdout) returns the standard output stream.
    • (io-stderr) returns the standard error stream.
  • Files
    • (io-file-read path) reads the whole contents of file at path or false if an error occurs.
    • (io-file-open path) opens file at path for reading.
    • (io-file-create path) opens file at path for writing and truncates the file or creates a new one.
    • (io-file-append path) opens file at path for appending or creates a new one.
  • Reading from streams
    • (io-read-byte io) reads a byte from stream io or returns false if the read was not successful (for example, end of file was reached).
    • (io-read-str io len) reads at most len bytes from stream io. If an error occurs (including end of file), less than len bytes may be returned.
    • (io-read-all-str io) reads all remaining bytes from stream io into a string.
    • (io-read-line io) reads a line terminated by \n (including the terminator if it is present).
    • (io-read-word io) reads a word separated by whitespace from stream io. The whitespace preceding the word is lost, but the whitespace following the word is left in the stream.
    • (io-read-int io) reads an integer from stream io. The integer can be preceded by whitespace and can have a sign, either + or -. Only decimal digits 0 to 9 are allowed, the integer ends at the first non-digit. However, the whitespace following the last digit is also consumed. If an integer could not be read, the function returns false.
    • (io-read-number io) reads a float with optional sign and exponent (denoted by e or E). Both the integer and the fractional parts are optional (so a single . is assumed to be 0). The whitespace following the number is consumed from the stream. If an error occurs, this function returns false.
  • Writing to streams
    • (io-write-byte io byte) writes byte into the stream io.
    • (io-write io x) writes into the stream io the stringified value x.
    • (io-write-line io x) writes into the stream io the stringified value x followed by a newline.