Tuples and lists in Erlang
Fixed shapes in braces, growing chains in brackets.
%% Tuples group fixed shapes; lists grow and shrink.
main(_) ->
Call = {call, 7, "5560199"},
{call, Line, Number} = Call,
io:format("Line ~p dials ~s~n", [Line, Number]),
Queue = [Call, {call, 3, "5560142"}],
Longer = [{busy, 9} | Queue],
io:format("Waiting: ~p~n", [length(Longer)]),
[First | Rest] = Longer,
io:format("Next up: ~p~n", [First]),
io:format("Behind it: ~p~n", [length(Rest)]).
How it works
{call, Line, Number}destructures by matching the shape.[Head | Tail]builds and splits lists.length/1walks the list; tuples know their size for free.
Keywords and builtins used here
formatlengthmain
The run, in numbers
- Lines
- 13
- Characters to type
- 394
- Tokens
- 135
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 125 seconds.
Step 3 of 3 in Values, step 3 of 31 in Language basics.