grand renaming to 'aqua' (well, 'Aqua' actually)
[aqualang.git] / examples / basics.aq
blob54ff820fcf7ea919a2fc1946001e812e0044145e
1 // examples of the basic syntax
3 // numbers are always doubles
4 pi = 3.14159
6 // string
7 greeting = "Hello World!"
9 // functions are first class citizens
10 square = func(x)
12     return x*x
15  // array types
16 arr = [pi, greeting, nil]
18 //replace the nil element (indices start at 0)
19 arr[2] = square
21 // append
22 arr += [23]
24 // use the size operator to find an arrays length
25 // or use arr.size()!
26 length = sizeof(arr)
28 // tables are associative containers that can use any object as key
29 table =
31     "pi" = 3.14159
32     23 = "twenty three"
33     "bar" = square
35 // equivalent to table["e"] = 2.71
36 table.e = 2.71
37 table.bar = func() { print(this.e, "\n") }
38 table.bar()
40 // flow control uses C style
41 if(pi > 2)
43     print("pi is greater than 2\n")
45 else
47     print("pi is less or equal 2\n")
50 x = 2
51 while(x < 1024)
53     print(x = square(x) ", ")
55 print("\n")
57 //no ++ or -- operators (... yet)
58 for(i=0; i<arr.size(); i+=1)
60     print(arr[i], ", ")
62 print("\n")
64 // for each syntax
65 for(value: arr)
67     print(value, ", ")
69 print("\n")
71 // for each on tables has no specific order
72 for(value: table)
74     print(value ", ")
76 print("\n")
78 // iterate over key value pairs
79 for(key, value : table)
81     print(key, " = ", value, ", ")
83 print("\n")