Variables and atoms in Erlang
Uppercase names bind once; lowercase bare words mean themselves.
%% Variables start uppercase and bind once; atoms are bare names.
main(_) ->
Operator = "Maud",
Shift = night,
io:format("~s works the ~p shift~n", [Operator, Shift]),
%% A bound variable only matches its own value.
Shift = night,
io:format("Still the ~p shift~n", [Shift]),
%% Atoms compare fast and mean themselves.
io:format("Ready? ~p~n", [Shift =:= night]),
io:format("Same as day? ~p~n", [Shift =:= day]).
How it works
Operatorbinds on first use and never rebinds.- Re-stating
Shift = nightis a match, not an assignment. =:=is exact equality; atoms compare in one step.
Keywords and builtins used here
formatmain
The run, in numbers
- Lines
- 13
- Characters to type
- 413
- Tokens
- 92
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 85 seconds.
Step 2 of 3 in Values, step 2 of 31 in Language basics.