-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.xen
More file actions
108 lines (88 loc) · 2.2 KB
/
Copy pathsyntax.xen
File metadata and controls
108 lines (88 loc) · 2.2 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
include io;
fn control_flow() {
var employee_one = ["John", 34];
var employee_two = ["Stacy", 28];
if (employee_one[1] > employee_two[1]) {
io.println(employee_one[0], " is older than ", employee_two[0]);
} else {
io.println(employee_one[0], " is younger than ", employee_two[0]);
}
}
fn operators() {
var x = 10;
io.println(x++); // '10'
io.println(++x); // '12'
var y = 20;
io.println(y--); // '20'
io.println(--y); // '18'
var z = 1;
z += 1;
z *= 2;
z -= 3;
z /= 4;
z %= 5;
io.println(z);
}
fn loops() {
var should_exit = false;
while (!should_exit) {
io.println("While loop body");
should_exit = true;
}
for (var i = 0; i < 1; i++) {
io.println("C-style for loop body");
}
for (var i in 0..1) {
io.println("Range-based for loop body");
}
var items = [1,2,3];
for (var item in items) {
io.print(item, " ");
}
io.print("\n");
}
fn lambdas() {
// Variable lambdas require semicolons at the end of their definition
const var add = fn(a, b) => a + b;
io.println(add(10, 20));
const var sub = fn(a, b) {
return a - b;
};
io.println(sub(10, 20));
// Anonymous functions do not require semicolons
fn exec(func) { func(); }
exec(fn() {
io.println("Anonymous function");
});
fn exec_args(func, args) {
io.println(func(args));
}
exec_args(fn(values) => values[1], [1, 2, 3]);
}
control_flow();
operators();
loops();
lambdas();
class Employee {
name = "";
age = 0;
gender = "";
private fn is_minor(age) {
return age < 18;
}
init(name, age, gender) {
if (this.is_minor(age)) {
return Error("Employee is under age");
}
this.name = name;
this.age = age;
this.gender = gender;
}
};
const var johnny = new Employee("Johnny", 17, "M");
if (johnny is Error) {
io.println("error: ", johnny.msg());
}
// Command line arguments (only available to scripts)
io.println(env.argc);
io.println(env.args);