WASDEV(The AI WorkShop)Docs Website Download

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

GADEnglish
montreprint a value
si, sinon, sinon siif, else, else if
finiend: closes every block
pandanwhile
pou chak … nanfor each … in
fè … akdefine an action with its parameters
retounenreturn
vre, fo, anyentrue, false, nothing
epi, oswa, paand, or, not
seis (equality)
plis pase, mwens pasegreater than, less than
ajoute, retireadd to, remove from
kanpe, kontinyebreak, continue
echèkstop with your own error message
eseye … si echwetry … catch
sèvi akuse a capability or another file
modèla record type with its rules
chak … nan … baymap
chak … nan … kotefilter
  • 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 … bay changes every item. chak … kote keeps 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