Variables¶
Déclaration¶
soit — Variable immuable¶
Une variable déclarée avec soit ne peut pas être réaffectée :
mutable — Variable modifiable¶
constante — Constante de compilation¶
Annotations de type¶
Les annotations de type sont optionnelles grâce à l'inférence :
// Sans annotation (inféré)
soit x = 42
// Avec annotation
soit x: entier = 42
soit nom: texte = "Alice"
soit notes: liste<entier> = [15, 18, 20]
Portée¶
Les variables sont visibles dans le bloc où elles sont déclarées et dans les sous-blocs :
soit extérieur = 1
fonction test()
soit intérieur = 2
afficher(extérieur) // OK : visible
afficher(intérieur) // OK : même bloc
fin
afficher(intérieur) // Erreur : hors de portée
Affectation¶
L'affectation modifie la valeur d'une variable mutable :
mutable x = 10
x = 20 // affectation simple
x += 5 // addition puis affectation (25)
x -= 10 // soustraction puis affectation (15)
x *= 2 // multiplication puis affectation (30)
x /= 3 // division puis affectation (10)
x %= 3 // modulo puis affectation (1)
Accès aux membres¶
soit point = (3, 4)
soit dico = ["clé": "valeur"]
// Accès par indice
soit premier = tableau[0]
// Accès par clé
soit val = dico["clé"]
Mot-clé comme¶
Le mot-clé comme permet le transtypage explicite :