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
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? ")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)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"Write a string to stdout with a trailing newline.
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()Read a line from stdin and return it (without the trailing newline). Returns empty string on EOF.
Write a string to stderr with a trailing newline.
Write a string to stdout without a trailing newline.