Open erl: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Run expressions in the Erlang shell and remember the final dot.
Open erl, run 2 + 3., and run one module call that ends with a dot.
Copy into erl and press Enter after each line
Notice the dot at the end of every runnable input.
%% An addition expression returns a number
2 + 3.
%% Call the string module to make text uppercase
string:uppercase("cat").
%% Call the io module to print a line
io:format("hello, BEAM~n", []).2 + 3. returns 5.
string:uppercase("cat"). returns "CAT".
io:format(...) prints a line, then shows ok. For now, read it as a “done” label.
Steps for the full example
- The final dot in
2 + 3.is not a decimal point. It ends the input. string:uppercase("cat").calls theuppercasefunction in thestringmodule.~nmeans a new line. The empty list[]says there are no extra values to put into the format string.
Original lesson notes
erl opens the Erlang shell. Like IEx, it lets you try a small piece of code at once.
The Erlang shell waits for a dot . before it knows an input is complete. If you forget the dot, it keeps waiting instead of running the code.
1> and 2> at the start of shell lines are prompts and input numbers. Do not copy them as code.
Symbols and terms
erl- Enter this in a terminal to open the Erlang shell.
1>- This is the shell prompt. Enter only the code after it.
.- Tell the shell: this input is complete, so run it.
- erl
- The terminal command that starts the Erlang shell.
- expression
- Code that produces a value when it runs, such as
2 + 3. - dot
- A complete shell input or function definition in Erlang ends with
..
Original full exercise
Ask the shell to multiply 8 by 7, then turn beam into uppercase text.
%% Add the operator, and do not forget the dot
8 ? 7.
%% Finish the function name
string:____("beam").First you should see 56, then "BEAM".
Show hint
Multiplication uses *. The function in the example was uppercase.
Show original answer
%% The star means multiplication
8 * 7.
%% Every complete input ends with a dot
string:uppercase("beam").You entered 2 + 3, but the shell is still waiting. What is probably missing?
The final dot is missing. Add . and press Enter.
Original lesson takeaways
erlopens the Erlang shell.- The shell is useful for trying short Erlang expressions.
- A complete shell input ends with a dot.