Erlang basics · Lesson 10 (open contents)
01 · Open erl02 · Meet common terms03 · Tell two kinds of text apart04 · Bind a variable once05 · Split and filter a list06 · Parse a number safely07 · Choose one path with case08 · Let a function keep going09 · Put code in a module10 · Compare terms and Boolean results11 · Read and update nested maps12 · Build and inspect UTF-8 binaries13 · Let clauses choose the function path14 · Solve a list twice15 · Choose with patterns, guards, and errors16 · Describe a module and one record17 · Put one tested module in Rebar318 · Return success or failure as data19 · Read and write one file safely20 · Build a data pipeline with functions21 · Keep records behind a module boundary22 · Define a module contract23 · Describe the data contract24 · Test small rules and whole flows25 · Shape builds and make a command26 · Write the project promise27 · Parse one real line28 · Keep the public API small29 · Make the promise executable30 · Package the edge and leave clues31 · Prove the project is done
ERLANG · FOUNDATION · LESSON 1025 minutes

Compare terms and Boolean results

Use arithmetic, strict equality, term order, and short-circuit Boolean operators.

01 · Start with the whole example

Run this first

Run it once, change one input, and compare the new result.

Erlang
%% Compare numeric types and Boolean paths
{2 == 2.0, 2 =:= 2.0, true andalso false, false orelse true}.
Check the result first
  • The result is {true,false,false,true}.
02 · Take the code apart

Read from the first line down

  1. Read == / =:=: Compare numerically or exactly.
  2. Read andalso: Continue only when the left Boolean is true.
  3. Read orelse: Use the right Boolean only when the left is false.
03 · Meet the new symbols

Symbols are not secret signs

== / =:=

Compare numerically or exactly.

andalso

Continue only when the left Boolean is true.

orelse

Use the right Boolean only when the left is false.

04 · Ideas inside the code

Match each name to its meaning

01

exact equality

=:= requires the same value and numeric type; == allows integer-float equality.

02

term order

Erlang defines an order across term types, though application code should not depend on memorizing it.

03

short circuit

andalso and orelse evaluate the right side only when needed, and their conditions are Boolean.

05 · Make the idea clear

Why these forms are useful

Run the example first. Predict one result, then change one input and run it again.

=:= requires the same value and numeric type; == allows integer-float equality.

Erlang defines an order across term types, though application code should not depend on memorizing it.

06 · Change it yourself

Close the answer and try

Check exact inequality and one short-circuit choice.

Practice starting point
{3 ____ 3.0, false ____ true}.

Target result: Return {true,true}.

Stuck? Read one hint

Use /= is not exact; use =/= and orelse.

After you run it, see one answer
One answer
{3 =/= 3.0, false orelse true}.
Think about it: Does Erlang treat every non-false term as a Boolean?

No. Boolean operators expect the atoms true or false.

Take with you

Remember these three lines

  1. 1

    Use exact comparison when type matters.

  2. 2

    Boolean operators need Boolean conditions.

  3. 3

    Do not build business rules from the global term order.

Lesson completeRun the code once, then mark this lesson as done.