2. Variables and Types
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/01-first-program.html. See also: book/chapters/05-types.html.
Goal
Declare a variable and understand its type.
Example
entry main at app/demo {
let age: int = 42
return age
}
Why it matters
An explicit type avoids a lot of invisible errors.
Quick check
If age becomes string, what should be changed?
Try this
- Create 2 variables (
int,string). - Return a simple value.
- Check for possible errors.
If you're stuck
Keep let nom: type = valeur everywhere at the start of learning.
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.