-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.txt
828 lines (714 loc) · 14.5 KB
/
tests.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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/*
let fac = fn(val) {
let impl = fn( val, acc ) {
if val > 1 {
impl( val - 1, acc * val )
} else {
acc
}
}
impl( val, 1 )
}
let fib = fn( n ) {
let x = fn(count) {
if count > 0 {
fn( ){ x(count - 1) }
} else {
fn( ){ return 15 }
}
}
let impl = fn( a, b, n ) {
if n > 0 {
impl( b, a + b, n -1 )
} else {
x(100)( );
a
}
}
impl(0, 1, n)
}
let fib = fn( n ) {
let impl = fn( a, b, n ) {
if(n > 0) {
impl( b, a + b, n -1 )
} else {
a
}
}
impl(0, 1, n)
}
let pow = fn( p ) {
let impl = fn(s, val, acc) {
if( val > 0 ) {
impl(s, val - 1, acc * s)
} else {
acc
}
}
return fn( s ) { impl(s, p, 1) }
}
let calls = {
true: fn( n ) {
let impl = fn( a, b, n ) {
if(n > 0) {
impl( b, a + b, n -1 )
} else {
a
}
}
impl(0, 1, n)
},
false: fn( n ) { n; }
}
let t = fn( x ) {
let m = fn( y ) {
y + 10
}
m( x + 1 )
}
let p = {"x": 0, "y": 0}
let t = {p: 1000}
t[{"x": 0, "y": 0}]
p["y"] = 1000
p["y"] = 0
let a = [[100], 1,2,3,4]
let m = {a: "Hello!"}
m[[[100], 1,2,3,4]]
let a = [1,2,3,4,5]
a[0] = a
let t = {a: 100}
let sum = fn( count ) { // start
let impl = fn( a, new ) { /// internal
//r(10)
if( new == 0 ) {
return a
} else {
if( true ) {
return impl( a + new, new - 1 )
}
return 100;
}
}
impl( 0, count )
}
let gr = fn(name) { fn( hello ) { hello + name } }
let t = gr("hello T")
let r = gr("hello R")
t( )
let x = fn(count){if(count > 0) { return x(count - 1) } else {0} }
let x = fn(count){if(count > 0) { return x(count - 1) + 1; 60 } 0 }
let x = fn( ){ x( ) }
let fac = fn( x ) { if(x > 1) { x * fac(x - 1) } else { 1 } }
let fib = fn(x) {
if (x == 0) { 0 } elif ( x==1 ) { 1 }
else { fib(x - 1) + fib(x - 2); }
};
/// it doesnt leak anymore =)
let z = fn(c) { let test = fn( ) { let a = [0, 1,2,3,4,5,6,7,8,9]; let b = a; let int = fn( ) { return a; }; let intA = int; let intB = int; return int } let copy_test = test( ); if(c>0) { test( ); return z(c - 1); } else { return copy_test; } }
let a = module { let z = fn(c) { let test = fn( ) { let a = [0, 1,2,3,4,5,6,7,8,9]; let b = a; let int = fn( ) { return a; }; let intA = int; let intB = int; return int } let copy_test = test( ); if(c>0) { test( ); return z(c - 1); } else { return copy_test; } } }
// Here is an array containing two hashes, that use strings as keys and integers
// and strings as values
let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}];
// We can also access hash elements with index expressions:
let getName = fn(person) { person["name"]; };
// And here we access array elements and call a function with the element as
// argument:
getName(people[0]); // => "Anna"
getName(people[1]); // => "Bob"
let create_array = fn( ) {
let a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
fn( ) { a }
}
let array = create_array( )
array( )[0] =
array( )[1] =
array( )[2] =
array( )[3] =
array( )[4] =
array( )[5] =
array( )[6] =
array( )[7] =
array( )[8] =
array( )[9] = 0.001
array( )
let test = fn( ) {
let a = [0, 1,2,3,4,5,6,7,8,9];
let b = a;
let i = fn( ) { [0, 1,2,3,4,5,6,7,8,9] }
let int = fn( ) { a }
int
}
let z = fn( c ) {
let test = fn( ) {
let a = [0, 1,2,3,4,5,6,7,8,9];
let b = a;
let i = fn( ) { [0, 1,2,3,4,5,6,7,8,9] }
let int = fn( ) { a }
int
}
let t = test( )
if c > 0 {
test( )
z(c-1)
} else {
test( )
}
}
let t = fn( ) { 10 }
let g = fn (name) {
{
false: fn( ) { "This is not true, " + name },
true: fn( ) { "This is true, " + name }
}
}
let f = g("first")
let a = [[f[false]], [f[true]]]
let a = [[f[false]], [{0: f[true]}]]
let a = [f[false], f[true]]
//f[false] = 0
let r = fn( ){ let bu = f; bu[true] }
let m = r( )
let test = fn( ) {
let a = [0, 1,2,3,4,5,6,7,8,9];
let t = test
fn( ) { a }
}
let m = fn( ) {
let r = test( )
r
}
let r = test( )
let z = fn(c) {
if(c>0) { test(); z(c - 1) } else { 0 }
}
let zz = fn( nn ) {
let impl = fn( n ) {
if( n > 0 ) {
test( )
test( )( )
impl( n - 1 )
} else {
test( )
}
}
impl( nn )
}
let x = "x"
let y = "y"
let z = "z"
let point = fn( x, y, z ) { {"x": x, "y": y, "z": z} }
let table = {
point(0, 0, 0): 0.0,
point(0, 0, 1): 0.1,
point(0, 1, 0): 0.2,
point(0, 1, 1): 0.3,
point(1, 0, 0): 0.4,
point(1, 0, 1): 0.5,
point(1, 1, 0): 0.6,
point(1, 1, 1): 0.7,
}
table[point(0, 1, 0)]
let call = fn( ) {
let gg = fn(name) {
let g = fn (name) {
{
false: fn( ) { "This is not true, " + name },
true: fn( ) { "This is true, " + name }
}
}
g(name)
}
let f = gg("first")
let a = fn( ) {
let b = f;
return b;
}
a
}
let call = fn( ) { let gg = fn(name) { let g = fn (name) { { false: fn( ) { "This is not true, " + name }, true: fn( ) { "This is true, " + name } } } g(name) } let f = gg("first") let a = fn( ) { let b = f; return b; } return a }
let bits = fn( value ) {
let impl = fn( val, acc ) {
if( val > 0 ) {
impl( val >> 1, acc + ( val & 2 ) )
} else {
acc
}
}
impl( value, 0 )
}
let test = fn(x, y) {
return x + y
}
let sum = fn(a, b, c) {
a + b + c
}
let get_sum = fn( n ) {
let impl = fn( a, b ) { a + b }
impl( n )
}
let s = get_sum(10);
(*s)(20, 30)
fn(a,b,c){a+b+c}
let a = fn( ) {
let z = 100 + 199
z
}
let d = fn(){ 200 + 100 }( )
let t = fn( n ) {
let impl = fn( c ) {
if( c > 0 ) {
if( true ) {
return impl( c - 1 )
}
} else {
return c
}
return "here we are!";
}
return impl(n)
}
let head = fn( arr ) {
if( len(arr) > 0 ) {
return arr[0]
}
}
let tail = fn( arr ) {
if( len(arr) > 1 ) {
let impl = fn( c, acc ) {
if( c < len(arr) ) {
return impl( c + 1, acc + [arr[c]] )
} else {
return acc
}
}
return impl(1, [])
} else {
[]
}
}
let reverse = fn( arr ) {
let impl = fn( acc ) {
if( arr != [] ) {
let h = head(arr)
arr = tail(arr)
impl( [h] + acc )
} else {
acc
}
}
return impl([])
}
let a = fn( len ) {
let impl = fn( accum, len ) {
if( len > 0 ) {
puts(len)
return impl(accum + [0], len - 1)
} else {
return accum
}
}
return impl([], len)
}
quote(unquote(8+8))
let qqq = quote(17 + 7)
quote( 7 + unquote(qqq) )
let bind = fn( call, param ) {
return fn( ) { call(param) }
}
quote(unquote(4 + 4) + 8)
quote(unquote(quote(4 + 4) ) + unquote(4+4) )
let t = quote(1000)
let ex = quote( unquote(t) + 1.0 )
let a = quote( fn( a ) { unquote(ex) + a } )
unquote(a)(1)
quote(unquote(quote(unquote(quote(unquote(quote(unquote(2+2))))))))
let m = macro(a, b, c) { unquote(a) + unquote(b) + unquote(c) }
let m = macro(a, b, c) {
let int = macro( ) {
unquote(a) + unquote(b) + unquote(c)
}
int( )
}
m(1,2,3)
let z = 100
let s = fn(a,b) { m( 1, 2, 3 ); a + b }
let sum = fn( a, b ) {
let smacro = macro ( a, b ) {
unquote(a) + unquote(b)
}
smacro(a, b)
}
let sum = macro( a, b ) { unquote( a ) + unquote( b ) }
let s = fn(a, b) {
a + b;
}
macro sum(a, b) { unquote(a) + unquote(b) }
macro eval_first( a, b ) { unquote(a) }
let unless = macro (cond, yes, no) {
if( !unquote(cond) ) {
unquote(yes)
} else {
unquote(no)
}
}
let plusToMinus = macro(infixExpression) {
unquote(left(infixExpression)) - unquote(right(infixExpression))
}
unless(10 > 5, puts("not greater"), puts("greater"))
s(sum(10, 10), 10)
let a = quote {
let b = 100
let c = 200
let d = 300
}
let ident = macro() {sum}
let ident() = fn(a,b){a+b}
macro a( ) {
let b = 100
let c = 200
let d = 300
}
macro set(init) {
unquote(init)
}
unquote(set(a))
let spin = fn( count ) {
if( count % 10000 == 0 ) {
puts(count)
}
if( count > 0 ) {
spin(count - 1)
} else {
"Ok"
}
}
let spin = fn( count ) {
if( count % 100000 == 0 ) {
return puts( count )
//fn(a, b){ a + b } (count + 100)
}
if( count > 0 ) {
spin(count - 1)
} else {
"Ok"
}
}
let spin = fn( count ) {
spin(count)
}
let sum = fn( a, b ) { a + b }
let a = quote( if(count == 666 ) { return sum(1, 665) } )
let spin = fn( count ) {
unquote(a)
if( count > 0 ) {
spin(count-1)
} else {
0
}
}
let spin = fn( count ) {
if( count % 10000 == 0 ) {
puts(count)
}
if( count > 0 ) {
spin(count - 1)
} else {
fn( a, b ) { a + b }
}
}
spin(1000000)
let name = macro( val ) {
let impl = macro( ) {
1 + 1
}
__I( val, 1 )
}
let fib = fn( n ) {
let impl = fn( a, b, c ) {
if( c > 0 ) {
impl( b, a + b, c - 1 )
} else {
a
}
}
impl( 0, 1, n )
}
let ra = fn( arr ) {
let impl = fn( res, id ) {
if( true ) {
puts(id)
impl( res, id + 1 )
} else {
res
}
}
impl( arr, 0 )
}
let sum = fn( ) {
let impl = fn( arr, acc, id ) {
if( id < len(arr) ) {
impl( arr, acc + arr[id], id + 1 )
} else {
acc
}
}
impl( __args, 0, 0 )
}
let sum = fn(a, b, ...args) { args }
let sum = fn(...) { *__args }
let sum = fn( ) {
let impl = fn( arr, acc, id ) {
if( id < len(arr) ) {
impl( arr, acc + arr[id], id + 1 )
} else {
acc
}
}
impl( __args, 0, 0 )
}
let arr_sum = fn( arr ) {
let impl = fn( arr, acc, id ) {
if( id < len(arr) ) {
impl( arr, acc + arr[id], id + 1 )
} else {
acc
}
}
impl( arr, 0, 0 )
}
let c1 = fn(c) {
if( c > 0 ) {
c2(c - 1)
} else {
"Ok 1"
}
}
let c2 = fn(c) {
if( c > 0 ) {
c1(c - 1)
} else {
"Ok 2"
}
}
module test {
let fib = fn( n ) {
let impl = fn( a, b, n ) {
if(n > 0) {
impl( b, a + b, n -1 )
} else {
a
}
}
impl(0, 1, n)
}
module int {
let inta = 777
}
let a = 1000
let b = 2000
let s = fn( c, e ){ c + e + a }
let ar = [1,2,3,4,5]
}
let a = 90
let a = module { let val1 = "value a" }
let b = module: a { let get = fn( ) { "form B: " + val1 } }
let c = module: b { let get = fn( ) { "form C: " + val1 } }
let d = module: c { let a = module { let ttt = "!" } let get = fn( ) { "form D: " + b.get( ) + a.ttt } }
let t = module: d {
let spin = fn( count ) {
if( count > 0 ) {
spin( count - 1 )
} else {
val1
}
}
}
test.s(10, 10)
let a = module : module { let val = 100 } { let get = fn( ) { val } }
let new = fn( val ) {
module {
let val = val
let get = fn( ) { val }
}
}
let a = module: new(100) { }
let b = module: new(200) { }
a.get( )
b.get( )
let a = module {
let val = 100
}
let new = fn( init ) {
module {
let val = init
}
}
let b = module: a, new(400) {
let get = fn( ) {
return val
}
}
__str(
for a,b,c in 1..2, -1 {
let test = a
return 100;
}
)
for v, i in [1, 2.2, "Hello!", -1.000001] {
io.puts(v, " ", i)
}
let s = fn( c ) {
if( c > 0 ) {
for i in 2 {
s(c - 1)
}
} else {
"Ok"
}
}
let sum = 0
let r = for val in [1,2,3,4,5,6,7] { sum = sum + val }
let t = { 1: "frst", 2: "sec", 3: "trd", 4.5: "frs" }
for k, v, i in t, -10 {
io.puts( k, " ", v, " ", i )
}
for i in 1..10 {
if( i == 9 ) {
let a = [1,2,3,4,5,6]
fn( ) { a }
}
}
for i in 20 {
if( i % 2 == 0 ) {
if( i == 8 ) {
io.puts("continue")
continue;
}
io.puts(i)
}
if( i == 14 ) {
break
}
}
let a = [1]
for i in a {
i = i + 1
io.puts(i)
__env()
}
for i in 100000000 {
if( i % 100000 == 0 ) {
if( i == 500000 ) {
continue
}
io.puts( i )
}
if( i == 666666 ) {
io.puts(i)
break
}
}
let map = fn( x, call ) {
for v in x {
v = call(v)
}
}
let r = map([1,2,3,4,5,6,7,8,9], fn(i){ i * i })
let r = map(1..9, fn(i){ i * i })
let z = map( {1:1, 2:2, 3:3, 4:4,5:5, 6:6, 7:7, 8:8, 9:9}, fn( i ) { i * i * i } )
let t = fn( max ) {
let res = {}
for i in 1..max+1 {
res = res + {i: i}
}
res
}
for i in 0..10, .1 {
io.puts(i)
}
let arr = []
for i in 1..5 {
arr = arr + [fn( ) {
let res = 1
for j in i {
io.puts(i, " ", res)
res = res * i
}
return res
} ]
}
arr[0]()
let t = fn( ) {
let a = [1,2,3,4,5]
fn( ) { a }
}
let a = t( )
let tt = fn( i ) {
fn( ) { i }
}
let test = fn ( ) {
let t = fn( ) {
let a = [1,2,3]
fn( ) { a }
}
let a = t( )
let b = t( )
a( )[0] = b
b = 0
a()
}
let make_pows = fn( max ) {
let res = [ ]
for i in 0..max {
res = res + [ fn( c ) {
let res = 1
for i in 1..i {
res = res * c
}
res
} ]
}
res
}
let a = macro( c ) {
if(true) { if(true) { if(true) {
unquote(c)
}}}
0
}
let a = macro(c) { unquote(c) + 3 }
let b = fn( c ) { a(c) }
let make_pows = fn( max ) {
let res = []
for i in 1..max {
res = res + [ fn( c ) { pow( c, i ) } ]
}
res
}
let a = fn( c ) { 1 * unquote(c) }
let sum = fn(a, b, c) { a + b + c}
let sum2 = sum(0)
let sum1 = (*sum2)(1, 2)
let sum3 = (*sum1)(1, 2)
let res0 = sum2(2, 3) // res0 = 5
for i in "Кирилица, latinic, 中國 จีน มีตัวละครจ πολλοί χαρακτήρες", -1 {
io.put(i)
}
io.puts( )
int
float
string
bool
char
function
null
rstring
table
array
module
ival<>
slice<>
quote
ref<>
type<>
*/