Erlang basics · Lesson 25 (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 · INTERMEDIATE · LESSON 2525 minutes

Shape builds and make a command

Use Rebar3 profiles for environments and an escript entry point for a small CLI.

01 · Start with the whole example

Run this first

Run it once, change one input, and compare the new result.

Erlang
%% cli.erl is the small command boundary
-module(cli).
-export([main/1]).
main(Args) ->
  lists:foreach(fun io:format/1, Args).

%% Then run: rebar3 escriptize
Check the result first
  • Rebar3 creates an executable under _build/default/bin/ when the escript settings are complete.
02 · Take the code apart

Read from the first line down

  1. Read {profiles, [...]}: Declare profile-specific configuration.
  2. Read {escript_main_app, app}: Choose the application containing main/1.
  3. Read rebar3 escriptize: Build the command under _build.
03 · Meet the new symbols

Symbols are not secret signs

{profiles, [...]}

Declare profile-specific configuration.

{escript_main_app, app}

Choose the application containing main/1.

rebar3 escriptize

Build the command under _build.

04 · Ideas inside the code

Match each name to its meaning

01

profile

A Rebar3 profile changes dependencies or options for a named environment such as test.

02

dependency

Dependencies belong in rebar.config, where Rebar3 can resolve repeatable versions.

03

escript

An escript packages BEAM code behind one executable command for a system with Erlang installed.

05 · Make the idea clear

Why these forms are useful

Run the example first. Predict one result, then change one input and run it again.

A Rebar3 profile changes dependencies or options for a named environment such as test.

Dependencies belong in rebar.config, where Rebar3 can resolve repeatable versions.

06 · Change it yourself

Close the answer and try

Print each argument followed by a newline.

Practice starting point
lists:foreach(fun(Arg) -> io:format("____", [Arg]) end, Args).

Target result: Use the format string ~s~n.

Stuck? Read one hint

~s prints text and ~n ends the line.

After you run it, see one answer
One answer
lists:foreach(fun(Arg) -> io:format("~s~n", [Arg]) end, Args).
Think about it: Does an escript include a complete Erlang runtime?

No. The target system still needs Erlang installed.

Take with you

Remember these three lines

  1. 1

    Keep environment options in profiles.

  2. 2

    Let Rebar3 resolve dependencies.

  3. 3

    Keep main/1 thin and move rules into normal modules.

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