4. Procedures

Level: beginner · Reading time: 3 min · Prerequisite: book/poche/03-conditions-and-loops.html · Last review: 2026-05-09

TL;DR (5 lines)

  • Read the core idea first.
  • Understand one concept at a time.
  • Run small examples.
  • Fix errors early.
  • Move to next chapter only when clear.

Frequent mistakes

  • Skipping prerequisites.
  • Reading without trying examples.
  • Fixing too many errors at once.

Prerequisites: book/poche/03-conditions-and-loops.html. See also: book/chapters/06-procedures.html.

Goal

Extract code into a reusable proc.

Example

proc add(a: int, b: int) -> int {
  give a + b
}

entry main at app/demo {
  return add(2, 3)
}

Why it matters

A procedure reduces duplication and makes code testable.

Quick check

What needs to be changed to add 3 numbers?

Try this

  1. Create mul(a, b).
  2. Call it from main.
  3. Compare results.

If you're stuck

A procedure = a clear objective + an explicit type of feedback.

See also

Next best action

Apply one idea from this chapter in a tiny example, then continue.