IO

is a module for performing I/O operations. Most functions found in this module are wrappers around the C standard library.

Raw

module

Module

wrappers for functions from the C standard library. Consider using a more carpesque function from IO when it exists. For detailed documentation please consult the documentation of your system (e.g. under Linux try man fprint).

color

defn

(Fn [Color.Id] ())

                        (color cid)
                    

sets the output color using ANSI coloration based on a color id cid.

colorize

defn

(Fn [Color.Id, (Ref String a)] ())

                        (colorize cid s)
                    

wraps a string in ANSI coloration based on a color id cid and prints it.

error

external

(Fn [(Ref String a)] ())

prints a string ref to stderr, does not append a newline.

errorln

external

(Fn [(Ref String a)] ())

prints a string ref to stderr, appends a newline.

fgetc

defn

(Fn [(Ptr FILE)] (Result Char String))

                        (fgetc file)
                    

gets a character from a file pointer (thin wrapper for the C standard library).

get-line

external

(Fn [] String)

gets a line from stdin.

getenv

defn

(Fn [(Ref String a)] (Maybe String))

                        (getenv s)
                    

gets the value of an environment variable (Carp-style wrapper for the C standard library)

open-file

defn

(Fn [(Ref String a), (Ref String b)] (Result (Ptr FILE) String))

                        (open-file filename mode)
                    

opens a file by name using a mode (e.g. [r]ead, [w]rite, [a]ppend), [rb] read binary...). See fopen() in the C standard library for a detailed description of valid parameters.

print

external

(Fn [(Ref String a)] ())

prints a string ref to stdout, does not append a newline.

println

external

(Fn [(Ref String a)] ())

prints a string ref to stdout, appends a newline.

read->EOF

defn

(Fn [(Ref String a)] (Result String String))

                        (read->EOF filename)
                    

reads a file given by name until the End-Of-File character is reached. Please consider using read-file instead, even though this works fine for UTF-8 encoded input files.

read-file

defn

(Fn [(Ref String a)] (Result String String))

                        (read-file filename)
                    

Reads the content of a file into a (Result String String). It is intended for text files, since the way to determine the length of a String is to use strlen() which probably will be inaccurate for binaries.

unsafe-read-file

external

(Fn [(Ref String a)] String)

returns the contents of a file passed as argument as a string. Note: there is no way to distinguish the output for an empty file and a missing file!

write-file

defn

(Fn [(Ref String a), (Ref String b)] (Result Bool String))

                        (write-file content file-name)
                    

Writes a string into a (text) file, overwriting it if it already exists.