typestar

The escript shape in Erlang

The smallest Erlang script: main/1 and io:format directives.

%% An escript runs main/1; io:format prints with ~ directives.
main(_) ->
    Exchange = "Kettle Street",
    Lines = 24,
    io:format("Exchange ~s on shift~n", [Exchange]),
    io:format("Lines available: ~p~n", [Lines]),
    io:format("Pairs if fully patched: ~p~n", [Lines div 2]).

How it works

  1. An escript runs main/1; the first line is always a comment.
  2. ~s formats strings, ~p pretty-prints any term.
  3. div is integer division — / would answer a float.

Keywords and builtins used here

The run, in numbers

Lines
7
Characters to type
265
Tokens
65
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 56 seconds.

Type this snippet

Step 1 of 3 in Values, step 1 of 31 in Language basics.

Next →