Elixir basics · Lesson 25 (open contents)
01 · Let the code speak02 · Meet six kinds of values03 · Put values together04 · Build a new list05 · Make the shapes match06 · Choose with case07 · Parse a number safely08 · Unpack &1 and the pipe09 · Put code in a project10 · Ask precise true-or-false questions11 · Read and update nested data12 · Count visible text and bytes13 · Let function clauses choose14 · Solve a list twice15 · Choose the smallest clear control form16 · Give domain data a shape17 · Put one tested module in Mix18 · Make success and failure predictable19 · Read and write one real file20 · Take only the data you need21 · Give different data one shared action22 · Write a callback contract23 · Write down the data contract24 · Test behavior and boundaries25 · Turn a project into 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
ELIXIR · INTERMEDIATE · LESSON 2525 minutes

Turn a project into a command

Add a custom Mix task and configure an escript entry point.

01 · Start with the whole example

Run this first

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

Elixir
# Run after configuring main_module in mix.exs
mix escript.build
./score_card 60 92 41
Check the result first
  • The executable receives three text arguments through main/1.
02 · Take the code apart

Read from the first line down

  1. Read escript: [main_module: App.CLI]: Choose the module that owns main/1.
  2. Read mix escript.build: Build the executable file.
  3. Read System.argv/0: Read command-line arguments inside a running VM when needed.
03 · Meet the new symbols

Symbols are not secret signs

escript: [main_module: App.CLI]

Choose the module that owns main/1.

mix escript.build

Build the executable file.

System.argv/0

Read command-line arguments inside a running VM when needed.

04 · Ideas inside the code

Match each name to its meaning

01

Mix task

A custom Mix task automates a project command under a namespaced task module.

02

escript

An escript packages BEAM bytecode behind one executable command for systems with Erlang installed.

03

entry point

The configured main/1 function receives command-line arguments.

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 custom Mix task automates a project command under a namespaced task module.

An escript packages BEAM bytecode behind one executable command for systems with Erlang installed.

06 · Change it yourself

Close the answer and try

Write a main/1 head that prints every argument on its own line.

Practice starting point
def main(args) do
  Enum.each(args, fn arg -> ____(arg) end)
end

Target result: Each argument should appear once.

Stuck? Read one hint

Use IO.puts/1.

After you run it, see one answer
One answer
def main(args) do
  Enum.each(args, fn arg -> IO.puts(arg) end)
end
Think about it: Does escript remove the need for Erlang?

No. The target system still needs an Erlang runtime.

Take with you

Remember these three lines

  1. 1

    Automate repeated project work with Mix tasks.

  2. 2

    Use main/1 as a small CLI boundary.

  3. 3

    Keep parsing and business rules outside the entry-point module.

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