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 (without the trailing newline; empty string on EOF, as read_line). Similar to Elixir's IO.gets/1, which keeps the newline.

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

Print show(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.

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

Write a string to stdout with a trailing newline.

IO.puts("Hello, " ++ name ++ "!")
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 (a CRLF line end is stripped too). Returns empty string on EOF, so an empty line and end of input look the same.

let line = IO.read_line()
if line == "" do IO.puts("(nothing)") else IO.puts("got: " ++ line) end
fnwarnwarn(s : String) : Unit#

Write a string to stderr with a trailing newline. Useful for diagnostics that should not mix with a program's stdout output.

IO.warn("config file not found, using defaults")
fnwritewrite(s : String) : Unit#

Write a string to stdout without a trailing newline.

IO.write("Loading... ")
IO.puts("done")