c(3)

✨ c ✨ β€” bestie, it's the command line interface module

okay so the module name is c and it lives in the Erlang manual, section 3 (c(3)). you're gonna love her, she's the shorthand queen. πŸ’…


🌸 NAME 🌸

c β€” Command line interface module. that's it, that's the name, she does exactly what it says on the tin, no cap. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

This module lets you type the short form of a bunch of commands you'd otherwise be typing the long way. Think of it as the group chat version of your Erlang tooling: same info, way fewer keystrokes. ✨

NOTE: these functions are meant for interactive use in the Erlang shell only. and the module prefix can be omitted. so like, you literally just type pwd(). and not c:pwd(). β€” the shell gets it, iykyk. πŸ™ˆ

πŸ‘€ See Also

filename, compile, erlang, yecc, xref β€” go give them a lil read, they're the supporting cast. 🫢


πŸŽ€ DATA TYPES πŸŽ€

no thoughts, just types. here's the roster:

cmd_line_arg() :: atom() | string().

h_return() ::
          ok | {error, missing | {unknown_format, unicode:chardata()}}.

hcb_return() :: h_return() | {error, callback_missing}.

hf_return() :: h_return() | {error, function_missing}.

ht_return() :: h_return() | {error, type_missing}.

they're giving "small but important", and honestly? slay. ⭐


πŸ”₯ FUNCTIONS πŸ”₯

this is the main character section. let's go, one by one, no skipping, periodt. 🌈


πŸ’œ bt(Pid) -> ok | undefined when Pid :: pid().

Stack backtrace for a process. Equivalent to erlang:process_display(Pid, backtrace).

so you hand her a pid and she gives you the backtrace, exactly like calling erlang:process_display(Pid, backtrace). simple, iconic. ✨


πŸ’œ c(Module) -> {ok, ModuleName} | error when Module :: file:name(), ModuleName :: module().

Works like c(Module, []).

literally just c(Module, []) with the vibes turned up. πŸŽ€


πŸ’œ c(Module, Options) -> {ok, ModuleName} | error

when

Module :: file:name(),
Options :: [compile:option()] | compile:option(),
ModuleName :: module().

Compiles and then purges and loads the code for a module. Module can be either a module name or a source file path, with or without .erl extension.

k so here's the tea β˜•, and you need to follow along because she's doing a lot of deciding:

  • If Module is a string, it's assumed to be a source file path, and the compiler will attempt to compile that source file with the options Options. If compilation fails, the old object file (if any) is deleted. 😭
  • If Module is an atom, a source file with that exact name or with .erl extension will be looked for. If found, it gets compiled with Options. If compilation fails, the old object file (if any) is deleted. same energy, different branch.
  • If Module is an atom and is not the path of a source file, then the code path is searched to locate the object file for the module and extract its original compiler options and source path. If the source file is not found in the original location, filelib:find_source/1 is used to search for it relative to the directory of the object file. πŸ”
  • The source file is compiled with the the original options appended to the given Options, the output replacing the old object file if and only if compilation succeeds. πŸ‘‘
⚠️ Notice that purging the code means that any processes lingering in old code for the module are killed without warning. for more information, see the code module. bestie this is not a drill, that's real, she will not knock first. πŸ’€

πŸ’œ c(Module, Options, Filter) -> {ok, ModuleName} | error

when

Module :: atom(),
Options :: [compile:option()],
Filter :: fun((compile:option()) -> boolean()),
ModuleName :: module().

Compiles and then purges and loads the code for module Module, which must be an atom.

The code path is searched to locate the object file for module Module and extract its original compiler options and source path. If the source file is not found in the original location, filelib:find_source/1 is used to search for it relative to the directory of the object file.

The source file is compiled with the the original options appended to the given Options, the output replacing the old object file if and only if compilation succeeds. The function Filter specifies which elements to remove from the original compiler options before the new options are added. The Filter fun should return true for options to keep, and false for options to remove. so like a lil bouncer at the door of your compile options 🫢

⚠️ Notice that purging the code means that any processes lingering in old code for the module are killed without warning. for more information, see the code module. yes she said it twice, because it matters twice. πŸ™ˆ

πŸ’œ cd(Dir) -> ok when Dir :: file:name().

Changes working directory to Dir, which can be a relative name, and then prints the name of the new working directory. she moves you AND announces it, main character behaviour fr fr. πŸ‘‘

Example:

2> cd("../erlang").
/home/ron/erlang

πŸ’œ erlangrc(PathList) -> {ok, file:filename()} | {error, term()} when PathList :: [Dir :: file:name()].

Search PathList and load .erlang resource file if found. cute lil scavenger hunt for your dotfile. πŸŽ€


πŸ’œ flush() -> ok.

Flushes any messages sent to the shell. clear the queue, clear the mind, self care ✨


πŸ’œ h(module()) -> h_return().

Print the documentation for Module. πŸ“–


πŸ’œ h(module(), function()) -> hf_return().

Print the documentation for all Module:Functions (regardless of arity). note: all of them, arity does NOT gatekeep here. πŸ’…


πŸ’œ h(module(), function(), arity()) -> hf_return().

Print the documentation for Module:Function/Arity. specific girl. precise. love that for her. 🎯


πŸ’œ hcb(module()) -> h_return().

Print the callback documentation for Module. πŸ¦‹


πŸ’œ hcb(module(), Callback :: atom()) -> hcb_return().

Print the callback documentation for all Module:Callbacks (regardless of arity). again, no arity filter, all are welcome. 🌸


πŸ’œ hcb(module(), Callback :: atom(), arity()) -> hcb_return().

Print the callback documentation for Module:Callback/Arity. one callback, one arity, one perfect lil answer. ⭐


πŸ’œ help() -> ok.

Displays help information: all valid shell internal commands, and commands in this module. your lil cheat sheet, absolute lifesaver 😭


πŸ’œ ht(module()) -> h_return().

Print the type documentation for Module. types deserve love too πŸ’œ


πŸ’œ ht(module(), Type :: atom()) -> ht_return().

Print the type documentation for Type in Module regardless of arity. all arities, no gatekeeping, we love to see it. 🌈


πŸ’œ ht(module(), Type :: atom(), arity()) -> ht_return().

Print the type documentation for Type/Arity in Module. laser focus. πŸŽ€


πŸ’œ i(X, Y, Z) -> [{atom(), term()}]

when

X :: non_neg_integer(),
Y :: non_neg_integer(),
Z :: non_neg_integer().

Old alias for pi(X, Y, Z). Note that the output of i(X, Y, Z) is very different from that of i(), so the new name is preferred.

⚠️ okay this one's a trap bestie πŸ’€ the old name i/3 outputs something totally different from i/0, which is exactly why pi(X, Y, Z) is the preferred glow-up. use the new name. periodt.

πŸ’œ l(Module) -> code:load_ret() when Module :: module().

Purges and loads, or reloads, a module by calling code:purge(Module) followed by code:load_file(Module).

⚠️ Notice that purging the code means that any processes lingering in old code for the module are killed without warning. for more information, see code/3. πŸ’€

πŸ’œ lc(Files) -> ok | error when Files :: [File :: cmd_line_arg()].

Compiles a list of files by calling compile:file(File, [report_errors, report_warnings]) for each File in Files. a lil assembly line of compiling, we love efficiency ✨

For information about File, see file:filename/0.


πŸ’œ lm() -> [code:load_ret()].

Reloads all currently loaded modules that have changed on disk (see mm/0). Returns the list of results from calling l(M) for each such M. she notices what changed and takes care of it, attentive queen πŸ‘‘


πŸ’œ ls() -> ok.

Lists files in the current directory. πŸ‘€


πŸ’œ ls(Dir) -> ok when Dir :: file:name().

Lists files in directory Dir or, if Dir is a file, only lists it. if you point at one file she's just gonna show you that one, no extras. πŸŽ€


πŸ’œ m() -> ok.

Displays information about the loaded modules, including the files from which they have been loaded. receipts, basically 🧾✨


πŸ’œ m(Module) -> ok when Module :: module().

Displays information about Module. πŸ“‹


πŸ’œ memory() -> [{Type, Size}] when Type :: atom(), Size :: non_neg_integer().

Memory allocation information. Equivalent to erlang:memory/0. 🧠✨


πŸ’œ memory(Type) -> Size when Type :: atom(), Size :: non_neg_integer(); (Types) -> [{Type, Size}] when

Types :: [Type],
Type :: atom(),
Size :: non_neg_integer().

Memory allocation information. Equivalent to erlang:memory/1. plugs straight into erlang:memory/1, no middleman πŸ’…


πŸ’œ mm() -> [module()].

Lists all modified modules. Shorthand for code:modified_modules/0. the "who changed?" report πŸ‘‘


πŸ’œ nc(File, Options) -> {ok, Module} | error

when

File :: file:name(),
Options :: [Option] | Option,
Option :: compile:option(),
Module :: module().

Compiles and then loads the code for a file on all nodes. Options defaults to []. Compilation is equivalent to:

compile:file(File, Options ++ [report_errors, report_warnings])

all nodes, bestie. all of them. network-wide slay 🌐πŸ”₯


πŸ’œ ni() -> ok.

i/0 displays system information, listing information about all processes. ni/0 does the same, but for all nodes in the network. same energy, wider net πŸ•ΈοΈ


πŸ’œ nl(Module) -> abcast | error when Module :: module().

Loads Module on all nodes. yeet it everywhere πŸš€


πŸ’œ pi(Pid) -> [{atom(), term()}] when Pid :: pid().

Displays information about a process, Equivalent to process_info(Pid), but location transparent. she finds the process wherever it's at, no questions asked 🫢


πŸ’œ pi(X, Y, Z) -> [{atom(), term()}]

when

X :: non_neg_integer(),
Y :: non_neg_integer(),
Z :: non_neg_integer().

Equivalent to pi(pid(X, Y, Z)). so it's just pi/1 with the pid built in for you. cute shortcut πŸŽ€


πŸ’œ pid(X, Y, Z) -> pid()

when

X :: non_neg_integer(),
Y :: non_neg_integer(),
Z :: non_neg_integer().

Converts X, Y, Z to pid <X.Y.Z>. This function is only to be used when debugging.

⚠️ only for debugging, okay? don't build your whole architecture on this one πŸ™ˆ

πŸ’œ pwd() -> ok.

Prints the name of the working directory. where am i? she'll tell you πŸ“βœ¨


πŸ’œ q() -> no_return().

This function is shorthand for init:stop(), that is, it causes the node to stop in a controlled fashion. the gracious exit. the goodbye. slay and farewell πŸ‘‹πŸ’…


πŸ’œ regs() -> ok.

regs/0 displays information about all registered processes. nregs/0 does the same, but for all nodes in the network. (yes, she mentions nregs/0 even though it's not in the list β€” that's just her being thorough, and we respect it.) πŸ‘‘


πŸ’œ uptime() -> ok.

Prints the node uptime (as specified by erlang:statistics(wall_clock)) in human-readable form. "how long have we been here?" and she answers in a way humans can actually read. iconic. ⏰


πŸ’œ xm(module() | file:filename()) -> XRefMRet :: term().

Finds undefined functions, unused functions, and calls to deprecated functions in a module by calling xref:m/1. your lil code-hygiene detective πŸ”βœ¨


πŸ’œ y(file:name()) -> YeccFileRet :: term().

Generates an LALR-1 parser. Equivalent to:

yecc:file(File)

For information about File = name(), see filename. For information about YeccRet, see yecc:file/2. parser generation but make it shorthand πŸ¦‹


πŸ’œ y(file:name(), [yecc:option()]) -> YeccFileRet :: yecc:yecc_ret().

Generates an LALR-1 parser. Equivalent to:

yecc:file(File, Options)

For information about File = name(), see filename. For information about Options and YeccRet, see yecc:file/2. same parser, now with your options πŸ’œ


🫢 THE SIGN-OFF 🫢

and that's the whole page, bestie!! this one came from Ericsson AB, shipping with stdlib 8.0.4, and it's page c(3) of the Erlang manual. go type some short commands and feel powerful. no cap, you ate this. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ‘‘

πŸ“¦ where this page comes from