SHOW:
|
|
- or go back to the newest paste.
| 1 | - | type ArrayOfNum = Array<Num> |
| 1 | + | # Syntaxe de Bootmonkey (BM) |
| 2 | # Par PifyZ, booti386, Gorgio et SuperMonkey | |
| 3 | - | const TOPICS_BY_PAGE = 20 |
| 3 | + | # Dernière mise à jour : 30/07/2014 |
| 4 | ||
| 5 | enum Volume {
| |
| 6 | LOW = 20, | |
| 7 | MEDIUM = 50, | |
| 8 | HIGH = 100 | |
| 9 | } | |
| 10 | ||
| 11 | interface Animal {
| |
| 12 | Void | |
| 13 | } | |
| 14 | ||
| 15 | class Point2D {
| |
| 16 | Num x, y | |
| 17 | ||
| 18 | new(Num x, Num y) {
| |
| 19 | @x = x | |
| 20 | @y = y | |
| 21 | } | |
| 22 | ||
| 23 | Void add(Num x, Num y) {
| |
| 24 | @x += x | |
| 25 | @y += y | |
| 26 | } | |
| 27 | ||
| 28 | Void add(Point2D p) {
| |
| 29 | @add(p.x, p.y) | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | class Point3D < Point2D {
| |
| 34 | Num z | |
| 35 | ||
| 36 | new(Num x, Num y, Num z) {
| |
| 37 | @(x, y) | |
| 38 | @z = z | |
| 39 | } | |
| 40 | ||
| 41 | Void add(Num x, Num y, Num z) {
| |
| 42 | @x += x | |
| 43 | @y += y | |
| 44 | @z += z | |
| 45 | } | |
| 46 | ||
| 47 | Void add(Point3D p) {
| |
| 48 | @add(p.x, p.y, p.z) | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | - | for i = 0 to 50 [ by 2 ] {
|
| 52 | + | if condition { } else if condition { } else { }
|
| 53 | - | |
| 53 | + | |
| 54 | # S'inspirer de : | |
| 55 | # - http://haxe.org/manual/lf-pattern-matching.html | |
| 56 | - | // Déclarer une variable |
| 56 | + | # - http://fr.wikibooks.org/wiki/OCaml/Structures#Filtrage_par_motifs |
| 57 | - | type nom_variable [ = valeur ] |
| 57 | + | switch value { when < 0 { } when < 5 { } when >= 5 { } }
|
| 58 | when ::= < 0 (inférieur) | <> 20 (différent) | 0 or 5 (ou) | 0 to 5 (entre (bornes includes)) | |
| 59 | - | // Déclarer une fonction |
| 59 | + | |
| 60 | # Boucles | |
| 61 | loop { }
| |
| 62 | - | // Déclarer une classe |
| 62 | + | loop 8 { }
|
| 63 | loop 8 by 2 { }
| |
| 64 | ||
| 65 | - | // Déclarer un attribut |
| 65 | + | while condition { }
|
| 66 | - | [public|ptotected|private] [static] [final] type nom_attribut [ = valeur ] |
| 66 | + | do { } while condition
|
| 67 | ||
| 68 | - | // Déclarer une méthode |
| 68 | + | for i = 0 to 8 { }
|
| 69 | for i = 0 to 8 by 2 { }
| |
| 70 | for _ = 0 to 8 by 2 { }
| |
| 71 | - | // La suite de fibonacci |
| 71 | + | |
| 72 | for in a_list { }
| |
| 73 | for _ in a_list { }
| |
| 74 | for _, _ in a_list { }
| |
| 75 | for v in a_list { }
| |
| 76 | for _, v in a_list { }
| |
| 77 | for k, _ in a_list { }
| |
| 78 | - | } |
| 78 | + | for k, v in a_list { }
|
| 79 | ||
| 80 | for in a_dict { }
| |
| 81 | for _ in a_dict { }
| |
| 82 | for _, _ in a_dict { }
| |
| 83 | for v in a_dict { }
| |
| 84 | for _, v in a_dict { }
| |
| 85 | for k, _ in a_dict { }
| |
| 86 | for k, v in a_dict { }
| |
| 87 | ||
| 88 | for in a_str { }
| |
| 89 | for _ in a_str { }
| |
| 90 | for _, _ in a_str { }
| |
| 91 | for v in a_str { }
| |
| 92 | for _, v in a_str { }
| |
| 93 | for k, _ in a_str { }
| |
| 94 | for k, v in a_str { }
| |
| 95 | ||
| 96 | _ est un mot-clé spécial qui permet de ne pas capturer une valeur ou de ne pas en envoyer | |
| 97 | ||
| 98 | # Déclarer un type | |
| 99 | "type" nom_type = type | |
| 100 | ||
| 101 | exemple : | |
| 102 | ||
| 103 | type Player = {
| |
| 104 | Str name, | |
| 105 | { Num x, Num y } position
| |
| 106 | } | |
| 107 | ||
| 108 | # Déclarer une variable | |
| 109 | [const] type nom_variable [ = valeur ] | |
| 110 | ||
| 111 | # Déclarer une fonction | |
| 112 | type nom_fonction(arguments) { }
| |
| 113 | ||
| 114 | # Déclarer une classe | |
| 115 | class NomClasse [ < NomClasseParente ] { }
| |
| 116 | ||
| 117 | # Déclarer un attribut | |
| 118 | [public|ptotected|private] [static|const] type nom_attribut [ = valeur ] | |
| 119 | ||
| 120 | # Déclarer une méthode | |
| 121 | [public|protected|private] [static] [final] type nom_methode(arguments) { }
| |
| 122 | ||
| 123 | # Suite de fibonacci | |
| 124 | Num fibo(Num n) {
| |
| 125 | if n <= 1 {
| |
| 126 | n | |
| 127 | } else {
| |
| 128 | fibo(n - 1) + fibo(n - 2) | |
| 129 | } | |
| 130 | } | |
| 131 | ||
| 132 | # Types | |
| 133 | Bool | |
| 134 | Num | |
| 135 | Chr | |
| 136 | Str | |
| 137 | List<T> | |
| 138 | Dict<V> | |
| 139 | Func<(T n)*>:T | |
| 140 | Obj | |
| 141 | Var | |
| 142 | (Null) | |
| 143 | ||
| 144 | Bool vaut true ou false | |
| 145 | Num est un nombre (int ou float confondus) | |
| 146 | Chr est un caractère : 'a', 'z' | |
| 147 | Str est une chaîne de caractère : "Hello World!", """Pour les textes comportant de nombreux guillemets""" | |
| 148 | List<T> est une liste de valeur : [ "Aymeric", "Guillaume", "Aurélie" ] | |
| 149 | Dict<V> est un dictionnaire clé-valeur : { "Aymeric": 18, "Guillaume": 15, "Aurélie": 21 }
| |
| 150 | Func<(T n)*>:T est une fonction : | |
| 151 | Obj est un objet : | |
| 152 | Var est un type dynamique non défini : | |
| 153 | Null est la valeur renvoyée quand la variable n'existe pas ou vaut Null |