lfe_io(3)
okay bestie, welcome to lfe_io(3) from the Library Functions Manual β¨ β this is the LFE io module, and itβs here to make input/output feel like a whole vibe, not a chore. Letβs get into it π
πΈ NAME πΈ
lfe_io β Lisp Flavoured Erlang (LFE) io functions π«Ά
β¨ SYNOPSIS β¨
This module provides a standard set of io functions for LFE. In the following description, many functions have an optional parameter IoDevice. If included, it must be the pid of a process which handles the IO protocols such as the IoDevice returned by file:open/2.
Two functions in this module are used to generate aesthetically attractive representations of abstract forms, which are suitable for printing. These functions return (possibly deep) lists of characters and generate an error if the form is wrong.
π DATA TYPES π
chars() = [char() | chars()]
prompt() = atom() | unicode:chardata()
filesexpr() = {Sexpr,Line}
The filesexpr() format is what lfe_io:parse_file/1 returns, and itβs used by the compiler to give better error information. Cute and useful? We love that for us π
π EXPORTS π
Hereβs the whole export lineup, bestie β no skips, no cuts β¨
get_line
get_line() -> Data | {error, ErrorInfo} | eof
get_line(Prompt) -> Data | {error, ErrorInfo} | eof
get_line(IoDevice, Prompt) -> Data | {error, ErrorInfo} | eof
Reads a line from the standard input (IoDevice), prompting it with prompt (Prompt). Note that this call guarantees that the input is saved in the input history. Iconic little guarantee, honestly π
read
read() -> {ok, Sexpr} | {error, ErrorInfo} | eof
read(Prompt) -> {ok, Sexpr} | {error, ErrorInfo} | eof
read(IoDevice, Prompt) -> {ok, Sexpr} | {error, ErrorInfo} | eof
Read an s-expr from the standard input (IoDevice) with a prompt (Prompt). Note that this is not line-oriented in that it stops as soon as it has consumed enough characters. Itβs giving βI know what I need, thanksβ energy π
read_line
read_line() -> {ok, Sexpr} | {error, ErrorInfo} | eof
read_line(Prompt) -> {ok, Sexpr} | {error, ErrorInfo} | eof
read_line(IoDevice, Prompt) -> {ok, Sexpr} | {error, ErrorInfo} | eof
Read the first s-expr from the standard input (IoDevice) with a prompt (Prompt). Note that this is line-oriented in that it reads whole lines, discarding left-over characters in the last line. Very βfinish your plateβ of it π
read_string
read_string(String) -> {ok, [Sexpr]} | {error, ErrorInfo}
Read all the s-exprs from String. Slay, string goblin π
print and print1
print(Sexpr) -> ok
print(IoDevice, Sexpr) -> ok
Print the s-expr Sexpr to the standard output (IoDevice).
print1(Sexpr) -> DeepCharList
Return the list of characters which represent the s-expr Sexpr.
prettyprint and prettyprint1
prettyprint(Sexpr) -> ok
prettyprint(IoDevice, Sexpr) -> ok
Pretty print the s-expr Sexpr to the standard output (IoDevice). Itβs the same s-expr, but with main character energy β¨
prettyprint1(Sexpr) -> DeepCharList
prettyprint1(Sexpr, Depth) -> DeepCharList
prettyprint1(Sexpr, Depth, Indentation) -> DeepCharList
prettyprint1(Sexpr, Depth, Indentation, LineLength) -> DeepCharList
Return the list of characters which represents the prettyprinted s-expr Sexpr. The default for Depth is 30, Indentation is 0, and LineLength is 80. Defaults understood, bestie π«Ά
format, fwrite, format1 and fwrite1
format(Format, Args) -> ok
format(IoDevice, Format, Args) -> ok
fwrite(Format, Args) -> ok
fwrite(IoDevice, Format, Args) -> ok
Print formatted output. The following commands are valid in the format string:
~w,~Wβ print LFE terms~p,~Pβ prettyprint LFE terms~sβ print a string~e,~f,~gβ print floats~b,~Bβ based integers~x,~Xβ based integers with a prefix~+,~#β based integers in vanilla erlang format~~β prints~~c,~n,~i
Currently they behave as for vanilla erlang except that ~w, ~W, ~p, ~P print the terms as LFE sexprs. Periodt π
format1(Format, Args) -> DeepCharList
fwrite1(Format, Args) -> DeepCharList
Return the formatted output with same arguments as format/fwrite.
read_file
read_file(FileName|Fd) -> {ok,[Sexpr]} | {error,ErrorInfo}
read_file(FileName|Fd, Line) -> {ok, [Sexpr]} | {error, ErrorInfo}
Read the file Filename or the already opened fileβs file descriptor Fd, returning a list of s-exprs. File-reading fairy vibes π§
parse_file
parse_file(FileName|Fd) -> {ok, [FileSexpr]} | {error, ErrorInfo}
parse_file(FileName|Fd, Line) -> {ok, [FileSexpr]} | {error, ErrorInfo}
where
FileSexpr = filesexpr()
Read the file Filename or the already opened fileβs file descriptor Fd, returning a list of pairs containing s-expr and line number of the start of the s-expr. The line numbers are giving βreceipts includedβ π₯
scan_sexpr
scan_sexpr(Cont, Chars) -> {done, Ret, RestChars} | {more, Cont1}
scan_sexpr(Cont, Chars, Line) -> {done, Ret, RestChars} | {more, Cont1}
This is a re-entrant call which scans tokens from the input and returns a parsed s-expr. If there are enough characters to parse a sexpr or it detects an error then it returns {done,...}, otherwise it returns {more,Cont} where Cont is used in the next call to scan_sexpr with more characters to try and parse a sexpr. This is continued until a sexpr has been parsed. Cont is initially [].
It is not designed to be called directly by an application but used through the i/o system where it can typically be called in an application by:
io:request(In, {get_until,unicode,Prompt,Module,scan_sexpr,[Line]})
π¨ ERROR INFORMATION π¨
The ErrorInfo mentioned above is the standard ErrorInfo structure which is returned from all IO modules. It has the following format:
{ErrorLine, Module, ErrorDescriptor}
A string describing the error is obtained with the following call:
apply(Module, format_error, ErrorDescriptor)
π AUTHORS π
- Robert Virding.
okay thatβs the whole page, bestie β the cute little footer says 2008-2024 and lfe_io(3), and honestly? iconic. mwah π
π¦ where this page comes from
- alpine 3.24: lfe-doc 2.2.0-r2 Β· Apache-2.0
- nixos 26.05: erlang27.3.4.19-lfe 2.2.0
- nixpkgs unstable: erlang27.3.4.19-lfe 2.2.2
- nixpkgs unstable: erlang28.5.0.8-lfe 2.2.2
- nixpkgs unstable: erlang29.1.2-lfe 2.2.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms