Tweaking the Environment

The Erlang shell has a number of built-in commands. You can see them all with the shell command help().

 
1>​ help().
 
** shell internal commands **
 
b() -- display all variable bindings
 
e(N) -- repeat the expression in query <N>
 
f() -- forget all variable bindings
 
f(X) -- forget the binding of variable X
 
h() -- history
 
...

All these commands are defined in the module shell_default.

If you want to define your own commands, just create a module called user_default. Here’s an example:

user_default.erl
 
-module​(user_default).
 
 
-compile​(export_all).
 
 
hello() ->
 
"Hello Joe how are you?"​.
 
 
away(Time) ->
 
io:format(​"Joe is away and will be back in ~w minutes~n"​,
 
[Time]).

Once this has been compiled ...

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.