-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax-figuring-out-zone.gpl
More file actions
135 lines (95 loc) · 2.46 KB
/
syntax-figuring-out-zone.gpl
File metadata and controls
135 lines (95 loc) · 2.46 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Variable Definition
myVar = 1; // Semicolons required?....
myVar1 = 2 + 3 + myVar; // standard c++ precedence
!myMutVar = 23; // Default everything is constant, ! to mark mutable
// Statically typed, all types are uppercase?
// Optionally, place the type after variable, usually type will be inferred
myTypedVar Int = 1;
args! := 23;
args! = 23;
args! = 23;
fn[x Int => Bool] {}// Int -> Bool
fn[x Int, y Int => Bool] {}// (Int, Int) -> Bool
fn[x Int => (Int, Bool)] {}// Int -> (Int, Bool)
fn[Bool] {}// () -> Bool
fn[=> Bool] {}// () -> Bool
fn[isA Bool=>] {}// Bool -> Void
fn[isB Bool =>] {}// Bool -> Void
fn[isC Bool => Void] {}// Bool -> Void
myOldTuple (Int, Float) = (1, .1);
myNewTuple Tuple(Int, Float) = .{ 1, .1 };
isPrime := fn[x Int => Bool] {
ran! Slice := range(0, x);
ran! ?Slice := range(0, x);
ran mut Opt(Slice) := [1, 2, 3];
ran = range(0, x - 1);
// Infered function type: fn[Bool=>]
while (cond) fn[e] {
}
for (rang) fn[e Int =>] {
if (x % e == 0) return true;
}
return x > 1;
}
std! := #use("std");
std = 2;
main := fn[] {
std.log("Hello, world!");
}
i Int := 10;
a Str := "hi";
f Float := 1.2;
s UInt := 1;
e UInt(32) := 12;
eat List(Int) := {1, 2, 3};
end Bool := true;
// Tuples
ee (Int, Float) := (10, 10.2)
be (Int, Float) := (10, 10.2)
beef := (10, 10.2)
InsteadBool := enum { DoIt, DontDoIt }
// Comptime types, proto, so on, Rigid
[ ]
// Tuple, Comptime length/types, but runtime values, Fluid
(a Int, b Float)
// function call is just passing a tuple to the function
func(a, b)
// Bind a type to a name
myFunc :: fn[a Int => Float, Int] {
}
// Assign a type instance (value) to a name
myVar = 1;
case[Int] { 0 => myFunc() }
MyEnum = enum {
}
add = f[a Int, b Int => Int] {
}
case {
}
// Keywords define blocks
struct[Traits], enum, fn(Proto), case(input), macro(Proto), union
// macro -> type reflection, text replacement, cool stuff, but not as crazy as C++, still just a function call
// Macros can return types, macros are used for generics, memoized
myTuple Tuple(Int, Float) := if (true) (10, 2.1) else (11, 2.3);
result Int := (as == 2);
res + 1;
asd := 1 + if(true) 2;
result := fn[a Int, b Float => Tuple(Int, Float)] {
x = x + 1;
}
if (true) var;
if (i == 2) {
result = 20;
result = 30;
} elif (i == 3) {
result := 30;
} else {
sult! := 40;
if (true) {
test = 2 + 1;
if (false) {
test = 2 + 1;
}
}
}
result! := 20;