Files
2026-03-09 23:09:46 -04:00

94 lines
2.0 KiB
Clojure

(ns io
"Erlang :io module — I/O protocol operations.
In CljElixir: (io/format \"Hello ~s!~n\" [\"world\"]), etc.
Lower-level than Elixir's IO module. Uses charlists and format strings.")
(defn format
"Formatted output (like C printf).
(io/format \"Hello ~s!~n\" [\"world\"]) ;=> prints 'Hello world!\\n'
(io/format device \"~p~n\" [term]) ;=> pretty-print to device
Common format specs:
~s string ~w write (Erlang term)
~p pretty-print ~f float
~e scientific ~b integer base 10
~.Xb integer base X ~n newline
~c character ~i ignore"
([format args])
([device format args]))
(defn fwrite
"Like format but returns :ok or {:error reason}."
([format args])
([device format args]))
(defn get-line
"Reads a line from standard input. Returns charlist or :eof.
(io/get-line \"prompt> \")"
([prompt])
([device prompt]))
(defn put-chars
"Writes characters to the IO device.
(io/put-chars \"hello\")"
([chars])
([device chars]))
(defn nl
"Writes a newline.
(io/nl)"
([])
([device]))
(defn read
"Reads an Erlang term from input. Returns {:ok term} or {:error reason}.
(io/read \"enter term> \")"
([prompt])
([device prompt]))
(defn write
"Writes an Erlang term.
(io/write {:a 1}) ;=> prints '{a,1}'"
([term])
([device term]))
(defn scan-erl-form
"Scans an Erlang form from input."
([prompt])
([device prompt])
([device prompt start-line]))
(defn parse-erl-form
"Parses an Erlang form from input."
([prompt])
([device prompt])
([device prompt start-line]))
(defn setopts
"Sets IO device options.
(io/setopts [{:encoding :unicode}])"
([opts])
([device opts]))
(defn getopts
"Gets IO device options."
([])
([device]))
(defn columns
"Returns the terminal column count.
(io/columns) ;=> {:ok 120}"
([])
([device]))
(defn rows
"Returns the terminal row count.
(io/rows) ;=> {:ok 40}"
([])
([device]))
(defn printable-range
"Returns the printable character range (:unicode or :latin1)."
[])