Home/Keyword dictionary
ELIXIR + ERLANG LEXICON

Not sure what it means?Look it up here.

Search for a term or an idea such as pattern matching, exceptions, or short circuiting. Each entry shows its kind, purpose, limits, and a tiny example.

Searchable dictionary

Find its job. See a tiny example.

Strictly reserved words appear first. Looking for defmodule, with, or -module? Choose the matching category.

Language

44 entries

Narrow the list by language or category

Elixir

15 strictly reserved words, common special forms, and Kernel macros

15 entries
afterStrictly reservedCleanup or timeout clause

Run cleanup before leaving, or set a maximum wait for a message.

try ... after runs cleanup before leaving the try block. receive ... after only ends this wait; it does not recall messages that were already sent.

try do
  work()
after
  cleanup()
end
andStrictly reservedStrict Boolean operator

Check whether two Boolean conditions are both true.

Both sides must be true or false. If the left side is false, the right side is not run. Use && when you need truthiness with other values.

ready? and enabled?
catchStrictly reservedCatch clause

Catch special signals such as throw and exit inside try.

Ordinary exceptions usually belong in rescue. catch mainly handles throw/1, process exits, and lower-level error classes.

try do
  throw(:stop)
catch
  :throw, reason -> reason
end
doStrictly reservedStart of a code block

Mark the code that belongs to the current function or decision.

Write several lines as do ... end. For one expression, you can use the shorter do: expression form.

if ready?, do: run()
elseStrictly reservedAlternative clause

Take another path when an earlier condition or match fails.

It can appear in if, unless, with, and try. Its trigger is slightly different in each construct.

if ok?, do: :yes, else: :no
endStrictly reservedEnd of a code block

Close a code block opened by do, fn, or another construct.

Indentation helps people read the code, but it is not syntax. A multiline block must end with end.

if ready? do
  run()
end
falseStrictly reservedBoolean literal

Represent “no” or a condition that does not hold.

Elixir treats only false and nil as falsy. Zero, an empty string, and an empty list are all truthy.

active? = false
fnStrictly reservedAnonymous function

Create a nameless function that can be passed to other code.

An anonymous function may have several pattern-matching clauses. After storing it in a variable, call it with the dot form: variable.(arguments).

double = fn x -> x * 2 end
double.(3)
inStrictly reservedMembership operator

Check whether a value belongs to a list or range.

in is also allowed in guards. It only tests membership; comprehensions use <- to draw values from a collection.

2 in 1..3
nilStrictly reservedEmpty-value literal

Show that there is no value here for now.

nil is the literal form of the atom :nil and is falsy in conditions. It often means “not found” or that an optional value is missing.

result = nil
notStrictly reservedStrict Boolean operator

Turn true into false and false into true.

not accepts only true or false. Use ! when you need to invert the truthiness of nil or other values.

not finished?
orStrictly reservedStrict Boolean operator

Check whether at least one of two Boolean conditions is true.

Both sides must be true or false. If the left side is true, the right side is not run. Use || for truthiness with other values.

cached? or fetch?()
rescueStrictly reservedException clause

Handle an ordinary exception from a try block by its type.

You can catch only named exceptions such as ArgumentError. An exception that does not match keeps travelling outward.

try do
  risky()
rescue
  ArgumentError -> :invalid
end
trueStrictly reservedBoolean literal

Represent “yes” or a condition that holds.

true is the literal form of the atom :true. It is also often the final cond branch, meaning “all remaining cases.”

enabled? = true
whenStrictly reservedGuard clause

After a pattern matches, check one more condition.

A guard after when may use only approved operators and functions. You cannot place any ordinary function there.

A way to picture itIt is like checking a name at the gate, then checking the entry rule. Both checks must pass.
def positive?(n) when n > 0, do: true

Erlang

29 strictly reserved words, common module attributes, and preprocessor directives

29 entries
afterStrictly reservedTimeout or cleanup clause

Stop waiting for a message after a limit, or clean up before leaving try.

receive ... after only stops the wait when time runs out. Expressions in try ... after run before the try expression is left.

receive
  Msg -> Msg
after 1000 ->
  timeout
end
andStrictly reservedStrict Boolean operator

Evaluate both sides, then check whether both are true.

Both sides must be Boolean values, and the right side always runs. Use andalso when the right side should not run after a false left side.

true and false. % false
andalsoStrictly reservedShort-circuit Boolean operator

Check the left side first, and continue only when it is true.

Both sides should produce Boolean values. Put a safety check first to avoid an unnecessary or unsafe calculation on the right.

A way to picture itFirst make sure the bridge is open, then send the cart across. If the first check fails, the next step never starts.
N > 0 andalso N rem 2 =:= 0.
bandStrictly reservedBitwise operator

Compare two integers bit by bit, keeping 1 only where both bits are 1.

It works only on integers. It is often used to read masks, flags, or selected bits in a binary protocol.

6 band 3. % 2
beginStrictly reservedExpression block

Group several calculations and treat them as one expression.

Separate the steps with commas. They run in order, and the whole begin ... end expression returns the value of the last step.

begin A = 1, A + 1 end.
bnotStrictly reservedBitwise operator

Flip every bit in the binary representation of an integer.

Erlang integers have no fixed 8-bit or 32-bit limit, so the result follows arbitrary-precision integer rules.

bnot 0. % -1
borStrictly reservedBitwise operator

Compare two integers bit by bit, producing 1 wherever either bit is 1.

It works only on integers and is often used to combine independent bit flags.

4 bor 1. % 5
bslStrictly reservedBit-shift operator

Move all bits in an integer several places to the left.

With a positive shift count, this usually acts like multiplication by the matching power of 2. It accepts only integers.

3 bsl 2. % 12
bsrStrictly reservedBit-shift operator

Move all bits in an integer several places to the right.

It accepts only integers. Negative integers use an arithmetic right shift, preserving their sign meaning.

12 bsr 2. % 3
bxorStrictly reservedBitwise operator

Compare two integers bit by bit, producing 1 where the bits differ.

Matching bits produce 0 and different bits produce 1. This is an integer bit operation, not Boolean xor.

6 bxor 3. % 5
caseStrictly reservedPattern branch

Run the first branch whose pattern fits the shape of a value.

case evaluates its target once, then tries the patterns and optional guards after of from top to bottom. It raises an error if nothing matches.

A way to picture itIt is like sorting letters by the mark on each envelope. The first matching rule decides where a letter goes.
case X of
  0 -> zero;
  _ -> other
end.
catchStrictly reservedException capture

Catch a thrown value or error and turn it into a result that code can handle.

It appears in the older catch Expression form and in a try catch clause. New code usually prefers the clearer structure of try.

Result = catch risky().
condStrictly reservedReserved but unused

Erlang reserves this name, but it cannot currently start a cond block.

cond cannot be used directly as an atom, variable, or function name. Write 'cond' when you need that atom, and use case or if for branches.

The current Erlang grammar does not use this word.
erl_scan:reserved_word('cond'). % true
divStrictly reservedArithmetic operator

Divide two integers and keep only the integer part.

The result is truncated toward zero, not rounded. A zero divisor raises a badarith error.

7 div 2. % 3
elseStrictly reservedmaybe failure branch

Decide what to do with a value that failed to match inside maybe.

The clauses after else still choose by pattern. This belongs only to maybe syntax; it is not a general if-else form.

Used with maybe expressions. Older OTP releases may not support it.
maybe {ok, V} ?= fetch(), V else error -> missing end.
endStrictly reservedEnd of an expression block

Close a case, fun, if, receive, try, or another block.

Indentation cannot close these expressions. Every opened multiline block needs an explicit end.

fun(X) -> X * 2 end.
funStrictly reservedAnonymous function or function reference

Create an anonymous function, or carry an existing function as a value.

An anonymous function may have several pattern clauses. fun Module:Function/Arity refers to an existing remote function.

Double = fun(X) -> X * 2 end.
ifStrictly reservedGuard branches

Check conditions from top to bottom and run the first branch whose guard is true.

An if condition must be an allowed guard expression, not any function call. If no branch matches, Erlang raises an if_clause error.

if N > 0 -> positive; true -> other end.
letStrictly reservedReserved but unused

Erlang reserves this name, but it has no usable let expression today.

Erlang binds variables through pattern matching. If you truly need an atom named let, write it as 'let'.

The current Erlang grammar does not use this word.
erl_scan:reserved_word('let'). % true
maybeStrictly reservedSequential matching expression

Line up several steps that may fail, and stop early when one does not match.

?= is used only inside maybe. A failed match returns the failing value, or passes it to else for a common result.

A way to picture itThink of a travel pass stamped at each stop. If one stamp is missing, the later steps wait.
maybe expressions arrived in Erlang/OTP 25. Older releases do not support them, and early releases may require the maybe_expr feature to be enabled.
maybe
  {ok, V} ?= fetch(),
  V
end.
notStrictly reservedBoolean operator

Turn true into false and false into true.

not accepts only Boolean values. Passing a number, atom, or another kind of value raises a badarg error.

not false. % true
ofStrictly reservedPattern-clause marker

Introduce branches that sort a case or try result by shape.

case uses of to introduce its branches. of is optional in try, where it handles only values returned normally by the try body.

case Value of ok -> done; _ -> retry end.
orStrictly reservedStrict Boolean operator

Evaluate both sides, then check whether at least one side is true.

Both sides must be Boolean values, and the right side always runs. Use orelse when the right side should not run after a true left side.

false or true. % true
orelseStrictly reservedShort-circuit Boolean operator

Check the left side first, and continue only when it is false.

Both sides should produce Boolean values. When the left side is already true, the right side does not run, so it works well for fallback conditions.

A way to picture itTry the short road first. If it is open, there is no need to inspect the backup road.
Cached orelse filelib:is_file(Path).
receiveStrictly reservedProcess message reception

Take the first message from the current process mailbox that fits a rule.

Messages are scanned in arrival order, and unmatched messages stay in the mailbox. Add after to avoid waiting forever.

A way to picture itIt is like taking the first acceptable letter from a stack. The other letters stay in the mailbox.
receive
  {ping, From} -> From ! pong
end.
remStrictly reservedArithmetic operator

Find the remainder after dividing two integers.

rem pairs with div and follows X = (X div Y) * Y + (X rem Y). A zero divisor raises an error.

7 rem 2. % 1
tryStrictly reservedException-handling expression

Handle a risky calculation, its successful result, its errors, and cleanup in one place.

try can combine of, catch, and after to handle normal values plus error, exit, and throw. An unmatched error keeps travelling outward.

try risky() catch _:Reason -> {error, Reason} end.
whenStrictly reservedGuard clause

After a pattern matches, check one more condition.

Only approved guard expressions may follow when. Ordinary functions cannot be placed there freely; a false condition moves on to the next clause.

A way to picture itFirst find the right group on the list, then check the age rule. Both checks must pass.
abs(N) when N < 0 -> -N.
xorStrictly reservedBoolean operator

Check whether exactly one of two Boolean values is true.

Both sides run and both must be Boolean values. Use bxor for an exclusive-or operation on every bit of two integers.

true xor false. % true
Classification

Similar shape. Different kind.

Reserved words, special forms, macros, and module attributes follow different rules. Learn the job first, then remember the category.

01Strictly reserved

Words reserved by the language

The language already uses these names, so an ordinary variable or function cannot reuse them.

Elixir: when · fn · do
Erlang: case · receive · fun
02Special forms

Built-in language constructs

They form Elixir's basic syntax and are handled directly by the compiler, but most are not strictly reserved words.

case · with · receive
alias · quote · unquote
03Macros, attributes, directives

Common macros and declarations

They look like keywords, but may really be macros, module attributes, or preprocessor directives.

defmodule · use · if
-module · -spec · -define
Official sources

Read this guide, then open the originals

This page follows the official references. Erlang maybe was disabled by default in OTP 25–26 and enabled by default from OTP 27. cond and let are reserved but still have no active grammar role.

Try a word in the Playground