Skip to content
Lesson 2 of 8

Step 1 of 5 · Reading · ~1 min

Learn

Syntax Basics

Variables in Erlang start with an UPPERCASE letter and are bound exactly once — you cannot reassign them. Lowercase identifiers are atoms — symbolic constants:

Name = "Ada",        % Variable
Age = 36,            % Variable
status = active,     % SYNTAX ERROR — lowercase isn't a variable
Status = active,     % OK — Status (var) bound to atom 'active'

Atoms are like enum values: their identity matters, not their contents. Common atoms: ok, error, true, false, undefined, nil.

Pattern matching is everywhere= doesn't assign, it asserts equality:

{X, Y} = {1, 2},     % Binds X=1, Y=2
[H | T] = [1, 2, 3], % H=1, T=[2,3]

Reading stdin:

Line = io:get_line(""),
%% strips trailing newline first:
Trimmed = string:trim(Line, trailing, "\n"),
N = list_to_integer(Trimmed)
Up nextDefining FunctionsFunctions and Pattern Matching

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…