Hello World
-module(main).
-export([hello/0]).
hello() ->
io:format("Hello, world!~n").
Compile and run in the Erlang shell:
c(main).
main:hello().
This defines a tiny Erlang module and a function that prints one line to the shell.
Variables
Variables are single-assignment and start with an uppercase letter.
Name = "Dan",
Count = 1,
Active = true.
These are single-assignment bindings. Once a variable has a value in Erlang, you do not mutate it in place.
Pattern Matching
greet({user, Name}) ->
io:format("Hello, ~s!~n", [Name]).
This matches a tuple argument and pulls the name out directly in the function head.