Erlang basics · Lesson 01 (open contents)
01 · Open erl02 · Meet common terms03 · Tell two kinds of text apart04 · Bind a variable once05 · Split and filter a list06 · Parse a number safely07 · Choose one path with case08 · Let a function keep going09 · Put code in a module10 · Compare terms and Boolean results11 · Read and update nested maps12 · Build and inspect UTF-8 binaries13 · Let clauses choose the function path14 · Solve a list twice15 · Choose with patterns, guards, and errors16 · Describe a module and one record17 · Put one tested module in Rebar318 · Return success or failure as data19 · Read and write one file safely20 · Build a data pipeline with functions21 · Keep records behind a module boundary22 · Define a module contract23 · Describe the data contract24 · Test small rules and whole flows25 · Shape builds and make a command26 · Write the project promise27 · Parse one real line28 · Keep the public API small29 · Make the promise executable30 · Package the edge and leave clues31 · Prove the project is done
ERLANG · SCRATCH · LESSON 0115 minutes

Open erl

Run expressions in the Erlang shell and remember the final dot.

01 · Start with the whole example

Copy into erl and press Enter after each line

Notice the dot at the end of every runnable input.

Erlang
%% 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", []).
Check the result first
  • 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.
02 · Take the code apart

Read from the first line down

  1. The final dot in 2 + 3. is not a decimal point. It ends the input.
  2. string:uppercase("cat"). calls the uppercase function in the string module.
  3. ~n means a new line. The empty list [] says there are no extra values to put into the format string.
03 · Meet the new symbols

Symbols are not secret signs

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.

04 · Ideas inside the code

Match each name to its meaning

01

erl

The terminal command that starts the Erlang shell.

02

expression

Code that produces a value when it runs, such as 2 + 3.

03

dot

A complete shell input or function definition in Erlang ends with ..

05 · Make the idea clear

Why these forms are useful

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.

06 · Change it yourself

Close the answer and try

Ask the shell to multiply 8 by 7, then turn beam into uppercase text.

Practice starting point
%% Add the operator, and do not forget the dot
8 ? 7.

%% Finish the function name
string:____("beam").

Target result: First you should see 56, then "BEAM".

Stuck? Read one hint

Multiplication uses *. The function in the example was uppercase.

After you run it, see one answer
One answer
%% The star means multiplication
8 * 7.

%% Every complete input ends with a dot
string:uppercase("beam").
Think about it: You entered `2 + 3`, but the shell is still waiting. What is probably missing?

The final dot is missing. Add . and press Enter.

Take with you

Remember these three lines

  1. 1

    erl opens the Erlang shell.

  2. 2

    The shell is useful for trying short Erlang expressions.

  3. 3

    A complete shell input ends with a dot.

Lesson completeRun the code once, then mark this lesson as done.