-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures.praia
More file actions
58 lines (50 loc) · 1.06 KB
/
features.praia
File metadata and controls
58 lines (50 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Test various Praia features
// Arithmetic & precedence
let x = 2 + 3 * 4
print("2 + 3 * 4 =", x) // 14
// String interpolation with expressions
let name = "Praia"
let version = 1
print("%{name} v%{version}")
// Truthiness: only nil and false are falsy
if (1) { print("1 is truthy") }
if ("") { print("empty string is truthy") }
if (0) { print("0 is truthy") }
if (nil) { print("BUG: nil should be falsy") }
if (false) { print("BUG: false should be falsy") }
// elif
let score = 85
if (score >= 90) {
print("A")
} elif (score >= 80) {
print("B")
} elif (score >= 70) {
print("C")
} else {
print("F")
}
// Functions with return values
func fib(n) {
if (n <= 1) { return n }
return fib(n - 1) + fib(n - 2)
}
print("fib(10) =", fib(10))
// Closures
func makeCounter() {
let count = 0
func increment() {
count = count + 1
return count
}
return increment
}
let counter = makeCounter()
print(counter())
print(counter())
print(counter())
// Postfix increment
let i = 0
i++
i++
i++
print("After 3 increments:", i)