
Chapter 1 · GAD language
The GAD language
The words of the language: values, conditions, loops, actions, lists and models, each with a short example.
Keywords
| GAD | English |
|---|---|
| montre | print a value |
| si, sinon, sinon si | if, else, else if |
| fini | end: closes every block |
| pandan | while |
| pou chak … nan | for each … in |
| fè … ak | define an action with its parameters |
| retounen | return |
| vre, fo, anyen | true, false, nothing |
| epi, oswa, pa | and, or, not |
| se | is (equality) |
| plis pase, mwens pase | greater than, less than |
| ajoute, retire | add to, remove from |
| kanpe, kontinye | break, continue |
| echèk | stop with your own error message |
| eseye … si echwe | try … catch |
| sèvi ak | use a capability or another file |
| modèl | a record type with its rules |
| chak … nan … bay | map |
| chak … nan … kote | filter |
- The language has 39 keywords. In WASDEV, the panel Language Libraries lists them all with an example.
Values, conditions and loops
non = "Ayiti"
laj = 34
montre "Bonjou {non}"
si laj pa mwens pase 18
montre "Granmoun"
sinon
montre "Timoun"
fini
k = 0
pandan k mwens pase 3
k ajoute 1
fini
- Equality is written
se, not=. The sign=only gives a value to a name. - A name can contain a hyphen:
nòt-yo. A subtraction needs spaces:a - b.
Actions
An action is a function. fè defines it, ak lists its parameters and retounen gives the answer.
fè kare ak n
retounen n * n
fini
montre kare(3)
Lists and dictionaries
nòt = [90, 85, 95]
elèv = { non: "Jira", nòt: nòt }
doub = chak n nan nòt bay n * 2
gwo = chak n nan nòt kote n plis pase 88
montre longè nòt, sonm(nòt), triye(nòt)
chak … baychanges every item.chak … kotekeeps the items where the condition is true.
Models that validate themselves
A model says which fields a record has and which rules they respect. You do not write the validation: the model already says it.
modèl Kont
non : tèks obligatwa
imel : imel obligatwa
modpas : tèks omwen 12
laj : nonb ant 13 ak 130
fini
k = Kont { non: "", imel: "pa-yon-imel", modpas: "kout", laj: 200 }
r = valide(k)
montre r.bon
pou chak p nan r.pwoblèm
montre p
fini
fo
`non` obligatwa, men li vid.
`imel` pa yon adrès imel valab : "pa-yon-imel".
`modpas` dwe gen omwen 12 karaktè, men li gen 4.
`laj` dwe ant 13 ak 130, men li 200.
Errors
echèk stops the program with your message. eseye … si echwe catches an error and lets the program continue.
eseye
kontni = fichye.li("konfig.txt")
si echwe erè
montre "Pa gen konfig : {erè}"
fini
