-
Notifications
You must be signed in to change notification settings - Fork 0
/
ideas.txt
94 lines (74 loc) · 2.12 KB
/
ideas.txt
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
1: 'variant' type for tagged unions:
type Value = variant {
integer: int,
floating: float,
boolean: b,
};
you can have enhanced switches with this:
mut val = Value{ .integer = 1 };
switch val
case .integer -> mut i {
i += 1;
// i is a mutable entity representing the .integer option of val
}
case .floating -> mut f {
f *= 2.5;
// mutable entity representing .floating option of val
}
case {
// default case, handles everything else
}
here, val == Value{.integer = 2}.
2: 'do' for a single statment in places you would usually want blocks.
if x == 1 {
print("wuh");
}
if x == 1 do print("wuh");
this applies to most language constructs, like switch cases and loops.
while x == 1 do print("wuh");
switch x
case 0 do print("its a zero!");
case 1 do print("its a one!");
case 2 {
printf("its a two!");
}
3: 'when' and 'which' for compile-time 'if' and 'switch' respectfully
when intrinsics::system == .windows {
let load_file = fn(...) {...}
}
which intrinsics::system
case .windows {
let load_file = fn(...) {...};
}
case .linux {
let load_file = fn(...) {...};
}
case .macos {
let load_file = fn(...) {...};
}
4: 'if' and 'switch' expressions (if `when` and `which` exist, they can also be used as expressions too)
// syntax ideas
let x = if a == b do 1 else 2;
let x = if a == b, 1 else 2;
let x = 1 if a == b else 2;
// idk about this syntax, give me ideas
let x = switch a
case 1 do 100
case 2 do 10
case do 1;
5: make switch syntax more similar to C's syntax (semantically the same though)
switch intrinsics::system {
case .windows:
let load_file = fn(...) {...};
// implicit break
case .linux:
let load_file = fn(...) {...};
case .macos:
let load_file = fn(...) {...};
}
// makes switch expression syntax better
mut x = switch a {
case 1: 100,
case 2: 10,
case: 1,
};