-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ee
312 lines (243 loc) · 6.57 KB
/
example.ee
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# include $"header.ee"
# print(file_name, " ", :boolstr(false), " ", :boolstr(true), "\n");
global primes = [2, 3, 5, 7, 11, 13, 17, 19];
global gech = "gech";
global array = [primes.0, [primes.1]];
global copy_element = array.1; # there's still no array.0.n; like syntax.
print(copy_element);
__print("Hello!\n");
print(to_string(50), " ",
to_string("50"),
"\n");
print(to_int(50), " ",
to_int("50"),
"\n");
global test_data = to_string((1 bls 10)); # 2 ^ 10
__print(test_data, "\n");
print(test_data, "\n");
print((5 bls 9), " ", (2 brs 5), (2 bxor 3), "\n");
print("current platform: ", platform(),
"\n",
"current cpu architecture: ", arch(), "\n");
enum =
Undefined,
String,
Decimal,
Array
;
f :type_of_to_string =
global __data = type_of($0);
if __data equal_to String =
return "string";
; elif __data equal_to Decimal =
return "decimal";
; elif __data equal_to Array =
return "array";
;
return "";
;
print(type_of(50), " ",
type_of("50"), " ",
type_of(["50"]), " ",
type_of(30 + 20), " ",
type_of(), " ",
:type_of_to_string(50), " ",
:type_of_to_string("50"), " ",
:type_of_to_string(["50"]), " ",
:type_of_to_string(30 + 20), " ",
:type_of_to_string(), " ",
"\n");
print(copy_element, "\n");
print(copy_element.0, "\n");
global x = "";
~x = array.1;
print(x, "\n");
delete "x";
print(x, "\n");
enum =
Zero,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
TheseDigitsAreEnoughForDoingMath
;
if (Zero is_in [Zero, One, Two, Three, Four]) equal_to true =
print("(Zero is_in [Zero, One, Two, Three, Four]) equal_to true\n");
;
print(Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, "\n");
if (((One equal_to One) and (Two equal_to Two))
or (Nine equal_to Zero)) equal_to true =
print("(((One equal_to One) and (Two equal_to Two)) or (Nine equal_to Zero)) equal_to true\n");
;
if (primes.0 + primes.1) equal_to primes.2 =
print(gech.0 + gech.1 + gech.2 + gech.3 + gech.4 + gech.5, "\n");
;
print(len(primes), " ", len(gech), "\n");
if argc equal_to 1 =
print(arg_0 + " - file reader\n",
"--------------------------\n",
arg_0 + " file\n");
; else =
if is_file(arg_1) equal_to true =
global data = read_file(arg_1);
print(data);
; elif path_exists(arg_1) equal_to true =
print(arg_1 + " seems like not a file\n");
; else =
print(arg_1 + " seems not in this directory\n");
;
;
f :split_by_chars =
global __var_index = 1;
global __split_keyword = "";
global __split_result = [];
global __lock_data = $0;
global __split_by = $1;
if type_of(__split_by) equal_to Array =
loopif __var_index not_equal_to len(__lock_data) + 1 =
if (__lock_data.(__var_index) is_in __split_by) equal_to true =
~__split_result = __split_result + __split_keyword;
~__split_keyword = "";
; else =
~__split_keyword = __split_keyword + __lock_data.(__var_index);
;
~__var_index = __var_index + 1;
;
; elif type_of(__split_by) equal_to String =
loopif __var_index not_equal_to len(__lock_data) + 1 =
if __lock_data.(__var_index) equal_to __split_by =
~__split_result = __split_result + __split_keyword;
~__split_keyword = "";
; else =
~__split_keyword = __split_keyword + __lock_data.(__var_index);
;
~__var_index = __var_index + 1;
;
; else =
loopif __var_index not_equal_to len(__lock_data) + 1 =
if __lock_data.(__var_index) equal_to " " =
~__split_result = __split_result + __split_keyword;
~__split_keyword = "";
; else =
~__split_keyword = __split_keyword + __lock_data.(__var_index);
;
~__var_index = __var_index + 1;
;
;
~__split_result = __split_result + __split_keyword;
delete ["__split_keyword",
"__var_index",
"__lock_data",
"__split_by"];
return __split_result;
;
print(:split_by_chars("Hello dear splitter guy", ["a", "e"]), "\n");
f :split =
delete ["__var_index",
"__split_keyword",
"__split_result",
"__lock_data"];
global __var_index = 1;
global __split_keyword = "";
global __split_result = [];
global __lock_data = $0;
loopif __var_index not_equal_to len($0) + 1 =
if __lock_data.(__var_index) equal_to " " =
~__split_result = __split_result + __split_keyword;
~__split_keyword = "";
; else =
~__split_keyword = __split_keyword + __lock_data.(__var_index);
;
~__var_index = __var_index + 1;
;
~__split_result = __split_result + __split_keyword;
return __split_result;
;
print(:split("Hello dear splitter guy"), "\n");
f :input =
global var = "";
global ch = "";
loopif ch not_equal_to "\n" =
~ch = char_input();
print(ch);
~var = var + ch;
;
return var;
;
print(len("Hello world\n"), "\n");
print(abs(-3), " ", abs(0), " ", abs(3), " ", abs(-3.7), " ", abs(3.7), "\n");
print(ceil(3.7), " ", floor(3.7), "\n");
print(log(16, 2), " ", log(0, 0), " ", log(16, 1), "\n");
print(sqrt(16), " ", sqrt(2), " ", sqrt(-1), "\n");
print(pi(), " ", e(), " ", pi() * e(), "\n");
print(to_lower("ENIGNE"), " ",
to_upper("lang"), " ",
starts_with("enigne"), " ",
ends_with("enigne"), " ",
starts_with("enigne") equal_to ends_with("enigne"), "\n");
if platform() not_equal_to "windows" =
print("type something: ", :input());
print("press any key to continue", char_input(), "\n");
;
f :generate =
global seed = $0;
~seed = ((6364136223846793005 * $0) + 1);
defer =
delete "seed";
print("result: "); # will be called after the evaluation of return, then the evaluated value will be returned.
;
return (seed % (($2 - $1) + 1)) + $1;
;
print(:generate(4, 5, 24), "\n");
global x = :generate(4, 5, 24); # handle_expr() will be called after the first use of x
print(x, "\n");
f :factorial =
global x = $0;
global result = 1;
loopif x not_equal_to 0 =
~result = result * x;
~x = x - 1;
;
defer =
delete [
"x",
"result"
];
;
return result;
;
f :fibonacci =
if $0 less_than 2 =
return $0;
;
global value = 1;
global n = $0;
loopif n not_equal_to 0 =
~value = value * 1.6180339887498949025257388711906969547271728515625;
~n = n - 1;
;
defer =
delete [
"value",
"n"
];
;
return round(value / sqrt(5));
;
global x = const_eval(print("Hello world\n"));
global y = const_eval(return(13));
global z = const_eval(13);
global q = const_eval(print(:factorial(5), "\n"));
global __c = const_eval(:factorial(5));
global __f = const_eval(print("output will be assigned to variable f\n"));
print(__c, "\n", __f);
print((y equal_to z), " ", y, " ", z, "\n");
print(:factorial(6), "\n", :fibonacci(11), "\n");
exit();
print("hmmmm\n");