4. Procedures
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
- Create
mul(a, b). - Call it from
main. - Compare results.
If you're stuck
A procedure = a clear objective + an explicit type of feedback.
Mini quiz
- What is the main goal of this chapter?
- Which concept is most important?
- What will you try right now?
See also
Next best action
Apply one idea from this chapter in a tiny example, then continue.