March Docs

IO

IO module: explicit I/O operations separate from Process.

Wraps the core print/read builtins under a clean IO namespace. All functions in this module operate on the standard streams (stdin, stdout, stderr) of the current OS process.

Usage: IO.puts("Hello!") -- write to stdout with newline IO.write("no newline") -- write to stdout, no newline IO.warn("something went wrong") -- write to stderr with newline let line = IO.read_line() -- read a line from stdin let b = IO.read_byte() -- read one raw byte from stdin (-1 on EOF) let x = IO.inspect(some_value) -- pretty-print and return value let line = IO.gets("Name: ") -- print prompt then read line

Functions

fngetsgets(prompt : String) : String#

Print prompt to stdout (no newline) then read and return a line from stdin. Equivalent to Elixir's IO.gets/1.

    let name = IO.gets("What is your name? ")
fninspectinspect(value : a) : a#

Pretty-print value to stdout (with newline) and return the value unchanged. Useful for mid-pipeline debugging, like Elixir's IO.inspect/2.

    some_list |> IO.inspect() |> Enum.map(fn x -> x + 1)
fniodata_to_stringiodata_to_string(iodata) : String#

Convert an IOList to a String by flattening all segments. Delegates to IOList.to_string/1.

    IO.iodata_to_string(IOList.from_string("hello"))  -- "hello"
fnputsputs(s : String) : Unit#

Write a string to stdout with a trailing newline.

fnread_byteread_byte() : Int#

Read a single raw byte from stdin (blocking, unbuffered) and return it as an Int in 0..255. Returns -1 on EOF.

Do not mix with `IO.read_line()`/`IO.gets()` in a compiled program: those
read through stdio's own buffer, while `read_byte` reads directly off the
file descriptor, so bytes already buffered by a prior line read are
invisible to it.

    let b = IO.read_byte()
fnread_lineread_line() : String#

Read a line from stdin and return it (without the trailing newline). Returns empty string on EOF.

fnwarnwarn(s : String) : Unit#

Write a string to stderr with a trailing newline.

fnwritewrite(s : String) : Unit#

Write a string to stdout without a trailing newline.