-
Notifications
You must be signed in to change notification settings - Fork 0
/
overview.lumpy
843 lines (684 loc) · 20.5 KB
/
overview.lumpy
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
# This is a comment.
# Comments begin with the # character and extend until the end of the line.
println("====================");
println("== Literal Values ==");
println("====================");
dumpln( null );
print("\n");
dumpln( true );
dumpln( false );
print("\n");
dumpln( 123 );
dumpln( 123.0 );
dumpln( 123.45 );
dumpln( 0xdeadbeef );
print("\n");
dumpln( "hello" );
dumpln( "hello world" );
dumpln( "hello\tworld" );
dumpln( "hello\nworld" );
dumpln( "hello\\world" );
dumpln( "hello\"world" );
dumpln( `hello world` );
dumpln(
`hello
world`
);
dumpln(
```
hello
world
```
);
dumpln( "hello, 世界" );
print("\n");
dumpln( [] );
dumpln( ["foo", "bar", "baz"] );
dumpln( ["foo", "bar", "baz",] );
print("\n");
dumpln( map{} );
dumpln( map{"foo": 123, "bar": 456, "baz": 789} );
dumpln( map{"foo": 123, "bar": 456, "baz": 789,} );
dumpln( {"foo": 123, "bar": 456, "baz": 789} );
dumpln( {"foo": 123, "bar": 456, "baz": 789,} );
print("\n");
dumpln( set{} );
dumpln( set{"foo", "bar", "baz"} );
dumpln( set{"foo", "bar", "baz",} );
dumpln( {"foo", "bar", "baz"} );
dumpln( {"foo", "bar", "baz",} );
print("\n");
dumpln( 123.& );
dumpln( {"foo": 123, "bar": 456, "baz": 456}.& );
print("\n");
let named_function = function() { };
dumpln( named_function );
dumpln( function() { } );
dumpln( function() { println("hello from inside a function"); } );
print("\n");
dumpln( dumpln );
dumpln( println );
print("\n");
println("===============");
println("== Accessors ==");
println("===============");
let v = [123, 456, 789];
println("v is " + repr(v));
println("v[1] is " + repr(v[1]));
try { v[3]; } else err { println("v[3] produces " + repr(err)); }
try { v["foo"]; } else err { println("v[\"foo\"] produces " + repr(err)); }
print("\n");
let m = {"foo": "bar", 123: {456, 789}, {"key": "val"}: "baz"};
println("m is " + repr(m));
println("m[\"foo\"] is " + repr(m["foo"]));
println("m[123] is " + repr(m[123]));
println("m[{\"key\": \"val\"}] is " + repr(m[{"key": "val"}]));
println("m::foo is " + repr(m::foo) + " (equivalent to m[\"foo\"])");
println("m.foo is " + repr(m.foo) + " (equivalent to m[\"foo\"] for field access)");
try { m["qux"]; } else err { println("m[\"qux\"] produces " + repr(err)); }
print("\n");
println("============================");
println("== Vector Value Semantics ==");
println("============================");
let k = ["y", 456];
println("k is " + repr(k));
println("let v be [[\"x\", 123], k, [\"z\", 789]]");
let v = [["x", 123], k, ["z", 789]];
println("v is " + repr(v));
println("set v[1][1] to \"foo\"");
v[1][1] = "foo";
println("k is " + repr(k));
println("v is " + repr(v));
print("\n");
let v1 = [["x", 123], ["y", 456], ["z", 789]];
println("v1 is " + repr(v1));
let v2 = v1;
println("let v2 be v1");
println("v2 is " + repr(v2));
println("set v2[1][1] to \"foo\"");
v2[1][1] = "foo";
println("v1 is " + repr(v1));
println("v2 is " + repr(v2));
print("\n");
println("=========================");
println("== Map Value Semantics ==");
println("=========================");
let k = {"y": 456};
println("k is " + repr(k));
println("let m be {\"a\": {\"x\": 123}, \"b\": k, \"c\": {\"z\": 789}}");
let m = {"a": {"x": 123}, "b": k, "c": {"z": 789}};
println("m is " + repr(m));
println("set m[\"b\"][\"y\"] to \"foo\"");
m["b"]["y"] = "foo";
println("k is " + repr(k));
println("m is " + repr(m));
print("\n");
let m1 = {"a": {"x": 123}, "b": {"y": 456}, "c": {"z": 789}};
println("m1 is " + repr(m1));
println("let m2 be m1");
let m2 = m1;
println("m2 is " + repr(m2));
println("set m2[\"b\"][\"y\"] to \"foo\"");
m2["b"]["y"] = "foo";
println("m1 is " + repr(m1));
println("m2 is " + repr(m2));
print("\n");
println("=========================");
println("== Set Value Semantics ==");
println("=========================");
let k = {"b", 456};
println("k is " + repr(k));
println("let s be {{\"x\", 123}, k, {\"c\", 789}}");
let s = {{"x", 123}, k, {"c", 789}};
println("s is " + repr(s));
println("insert \"foo\" into k");
k.insert("foo");
println("k = " + repr(k));
println("s = " + repr(s));
print("\n");
println("===============");
println("== Operators ==");
println("===============");
println("operator + (unary)");
println("+123 is " + repr(+123));
println("+-123 is " + repr(+-123));
print("\n");
println("operator - (unary)");
println("-123 is " + repr(-123));
println("--123 is " + repr(--123));
print("\n");
println("operator not");
println("not true is " + repr(not true));
println("not false is " + repr(not false));
print("\n");
println("operator ==");
println("123 == 123 is " + repr(123 == 123));
println("123 == 456 is " + repr(123 == 456));
println("\"foo\" == \"foo\" is " + repr("foo" == "foo"));
println("\"foo\" == \"bar\" is " + repr("foo" == "bar"));
println("123 == \"foo\" is " + repr(123 == "foo"));
print("\n");
println("operator !=");
println("123 != 123 is " + repr(123 != 123));
println("123 != 456 is " + repr(123 != 456));
println("\"foo\" != \"foo\" is " + repr("foo" != "foo"));
println("\"foo\" != \"bar\" is " + repr("foo" != "bar"));
println("123 != \"foo\" is " + repr(123 != "foo"));
print("\n");
println("operator <=");
println("123 <= 123 is " + repr(123 <= 123));
println("123 <= 456 is " + repr(123 <= 456));
println("\"foo\" <= \"foo\" is " + repr("foo" <= "foo"));
println("\"foo\" <= \"bar\" is " + repr("foo" <= "bar"));
print("\n");
println("operator >=");
println("123 >= 123 is " + repr(123 >= 123));
println("123 >= 456 is " + repr(123 >= 456));
println("\"foo\" >= \"foo\" is " + repr("foo" >= "foo"));
println("\"foo\" >= \"bar\" is " + repr("foo" >= "bar"));
print("\n");
println("operator <");
println("123 < 123 is " + repr(123 < 123));
println("123 < 456 is " + repr(123 < 456));
println("\"foo\" < \"foo\" is " + repr("foo" < "foo"));
println("\"foo\" < \"bar\" is " + repr("foo" < "bar"));
print("\n");
println("operator >");
println("123 > 123 is " + repr(123 > 123));
println("123 > 456 is " + repr(123 > 456));
println("\"foo\" > \"foo\" is " + repr("foo" > "foo"));
println("\"foo\" > \"bar\" is " + repr("foo" > "bar"));
print("\n");
println("operator +");
println("123 + 456 is " + repr(123 + 456));
println("\"foo\" + \"bar\" is " + repr("foo" + "bar"));
print("\n");
println("operator -");
println("123 - 456 is " + repr(123 - 456));
print("\n");
println("operator *");
println("123 * 456 is " + repr(123 * 456));
print("\n");
println("operator /");
println("123 / 456 is " + repr(123 / 456));
try { 123 / 0; } else err { println("123 / 0 produces " + repr(err)); }
print("\n");
println("operator %");
println("+7 % +3 is " + repr(+7 % +3));
println("+7 % -3 is " + repr(+7 % -3));
println("-7 % +3 is " + repr(-7 % +3));
println("-7 % -3 is " + repr(-7 % -3));
println("10 % 3.5 is " + repr(10 % 3.5));
println("123 % Inf is " + repr(123 % Inf));
try { 123 % 0; } else err { println("123 % 0 produces " + repr(err)); }
print("\n");
println("operator .&");
println("123.& is " + repr(123.&));
print("\n");
println("operator .*");
println("123.&.* is " + repr(123.&.*));
println("let x be map{}");
let x = map{};
println("let y be x.&");
let y = x.&;
println("set y.*[\"foo\"] to \"bar\"");
y.*["foo"] = "bar";
println("x is " + repr(x));
print("\n");
println("operator Precedence");
let tmp = (123 + 456) * 789 + map{"x": 3.14}["x"];
println("(123 + 456) * 789 + map{\"x\": 3.14}[\"x\"] evaluates to " + repr(tmp));
print("\n");
println("==========================");
println("== Operator Overloading ==");
println("==========================");
let person = {
"new": function(name, age) {
let self = {"name": name, "age": age};
setmeta(self.&, person);
return self;
},
"unary+": function(value) {
println("unary+ called with " + repr(value));
return alice; # arbitrary
},
"unary-": function(value) {
println("unary- called with " + repr(value));
return alice; # arbitrary
},
"not": function(value) {
println("not called with " + repr(value));
return alice; # arbitrary
},
"and": function(lhs, rhs) {
println("and called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
"or": function(lhs, rhs) {
println("or called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
"==": function(lhs, rhs) {
println("== called with " + repr(lhs) + " and " + repr(rhs));
return lhs.name == rhs.name and lhs.age == rhs.age;
},
"!=": function(lhs, rhs) {
println("!= called with " + repr(lhs) + " and " + repr(rhs));
return not (lhs.name == rhs.name and lhs.age == rhs.age);
},
"<=": function(lhs, rhs) {
println("<= called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
">=": function(lhs, rhs) {
println(">= called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
"<": function(lhs, rhs) {
println("< called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
">": function(lhs, rhs) {
println("> called with " + repr(lhs) + " and " + repr(rhs));
return false; # arbitrary
},
"+": function(lhs, rhs) {
println("+ called with " + repr(lhs) + " and " + repr(rhs));
return alice; # arbitrary
},
"-": function(lhs, rhs) {
println("- called with " + repr(lhs) + " and " + repr(rhs));
return alice; # arbitrary
},
"*": function(lhs, rhs) {
println("* called with " + repr(lhs) + " and " + repr(rhs));
return alice; # arbitrary
},
"/": function(lhs, rhs) {
println("/ called with " + repr(lhs) + " and " + repr(rhs));
return alice; # arbitrary
},
"%": function(lhs, rhs) {
println("% called with " + repr(lhs) + " and " + repr(rhs));
return alice; # arbitrary
},
};
println("person is " + repr(person));
print("\n");
println("let alice be the result of person::new(\"Alice\", 32)");
let alice = person::new("Alice", 32);
println("alice is " + repr(alice));
println("getmeta(alice) is " + repr(getmeta(alice)));
print("\n");
println("let bob be the result of person::new(\"Bob\", 27)");
let bob = person::new("Bob", 27);
println("bob is " + repr(bob));
println("getmeta(bob) is " + repr(getmeta(bob)));
print("\n");
println("calling overloadable operators on alice and bob");
+alice;
-alice;
not alice;
alice and bob;
alice or bob;
alice == bob;
alice != bob;
alice <= bob;
alice >= bob;
alice < bob;
alice > bob;
alice + bob;
alice - bob;
alice * bob;
alice / bob;
alice % bob;
print("\n");
let vec2 = {
"new": function(x, y) {
let self = {"x": x, "y": y};
setmeta(self.&, vec2);
return self;
},
"unary+": function(value) {
println("unary+ called with " + string(value));
return value;
},
"unary-": function(value) {
println("unary- called with " + string(value));
value.x = -value.x;
value.y = -value.y;
return value;
},
"compare": function(lhs, rhs) {
println("compare called with " + string(lhs) + " and " + string(rhs));
if lhs.x < rhs.x { return -1; }
if lhs.x > rhs.x { return +1; }
if lhs.y < rhs.y { return -1; }
if lhs.y > rhs.y { return +1; }
return 0;
},
};
println("vec2 is " + repr(vec2));
print("\n");
println("let a be the result of vec2::new(-3, +5)");
let a = vec2::new(-3, +5);
println("a is " + repr(a));
println("getmeta(a) is " + repr(getmeta(a)));
print("\n");
println("let b be the result of vec2::new(+1, +0)");
let b = vec2::new(+1, +0);
println("b is " + repr(b));
println("getmeta(b) is " + repr(getmeta(b)));
print("\n");
println("calling overloadable comparison operators on a and a");
dumpln(a == a);
dumpln(a != a);
dumpln(a <= a);
dumpln(a >= a);
dumpln(a < a);
dumpln(a > a);
print("\n");
println("calling overloadable comparison operators on a and b");
dumpln(a == b);
dumpln(a != b);
dumpln(a <= b);
dumpln(a >= b);
dumpln(a < b);
dumpln(a > b);
print("\n");
println("========================");
println("== If, Elif, and Else ==");
println("========================");
if true {
println("A (if)");
}
if false {
println("X");
}
elif true {
println("B (elif)");
}
if false {
println("X");
}
elif false {
println("X");
}
if false {
println("X");
}
elif false {
println("X");
}
elif true {
println("C (second-elif)");
}
if false {
println("X");
}
elif false {
println("X");
}
else {
println("D (else)");
}
print("\n");
println("===========");
println("== Loops ==");
println("===========");
println("Integer Loop: for x in 3");
for x in 3 {
println("x is " + repr(x));
}
print("\n");
println("Integer Loops With References Are Not Permitted: for reference x in 3");
try {
for k.& in 3 { }
}
else err {
println("error: " + string(err));
}
print("\n");
let v = ["a", "b", "c"];
println("Vector Loop: for x in " + repr(v));
for x in v {
println("x is " + repr(x));
}
print("\n");
let v = [{"value": 123}, {"value": 456}, {"value": 789}];
println("Vector Loop With References: for reference x in vector " + repr(v) + " increment x.*.value by one");
for x.& in v {
x.*.value = x.*.value + 1;
}
println("vector post-loop is " + repr(v));
print("\n");
let m = map{"a": 123, "b": 456, "c": 789};
println("Map Loop: for k, v in " + repr(m));
for k, v in m {
println("k is " + repr(k) + ", " + "v is " + repr(v));
}
print("\n");
let m = {{"id": 123}: "foo", {"id": 456}: "bar", {"id": 789}: "baz"};
println("Map Loops With Key References Are Not Permitted: for reference k in map " + repr(m));
try {
for k.& in m { }
}
else err {
println("error: " + string(err));
}
print("\n");
let m = {"foo": {"value": 123}, "bar": {"value": 456}, "baz": {"value": 789}};
println("Map Loops With Value References: for k, reference v in map " + repr(m) + " increment v.*.value by one");
for k, v.& in m {
v.*.value = v.*.value + 1;
}
println("map post-loop is " + repr(m));
print("\n");
let s = set{"a", "b", "c"};
println("Set Loop: for x in " + repr(s));
for x in s {
println("x is " + repr(x));
}
print("\n");
let s = {{"value": 123}, {"value": 456}, {"value": 789}};
println("Set Loops With References Are Not Permitted: for reference x in set " + repr(s));
try {
for x.& in s { }
}
else err {
println("error: " + string(err));
}
print("\n");
println("let x be 1");
let x = 1;
println("while x <= 5 print x and then increment x by 1");
while x <= 5 {
println("x is " + repr(x));
x = x + 1;
}
print("\n");
println("Break: while true break");
while true {
break;
}
print("\n");
let v = ["foo", "bar", "baz"];
println("Continue: for x in " + repr(v) + " continue before an error occurs");
for x in v {
continue;
error "oopsie";
}
print("\n");
println("======================================");
println("== Scoping, Functions, and Closures ==");
println("======================================");
let hello = function() {
println("hello from inside a function");
};
hello();
print("\n");
println("let x be 123");
let x = 123;
println("open a new scope");
if true {
println("\tlet x be 456 inside the new scope");
let x = 456;
println("\tinside the scope x is " + repr(x));
}
println("outside the scope x is " + repr(x) + " due to lexical scoping");
print("\n");
println("let x be 123");
let x = 123;
println("open a new scope");
if true {
println("\tset x to 456 inside the new scope (using assignment without let)");
x = 456;
println("\tinside the scope x is " + repr(x));
}
println("outside the scope x is " + repr(x));
print("\n");
println("let x be 123");
let x = 123;
function() {
println("\tset x to 456 from within a function (using assignment without let)");
x = 456;
println("\tinside the function x is " + repr(x));
}();
println("outside the function x is " + repr(x));
print("\n");
println("create a function `adder(x)` returning a `function(y)` that returns the sum of the closed-over x and argument y when invoked");
let adder = function(x) {
return function(y) {
return x + y;
};
};
println("adder is " + repr(adder));
println("let add1 be adder(1)");
let add1 = adder(1);
println("add1 is " + repr(add1));
println("add1(2) is " + repr(add1(2)));
print("\n");
let x = map{
"a": 123,
"f": function(self) {
println("\t[inside f] self is " + repr(self));
println("\t[inside f] self.*.a is " + repr(self.*.a));
},
};
println("x is " + repr(x));
println("x[\"f\"] is a function with a single `self` parameter");
println("calling x[\"f\"] as x[\"f\"](x.&)");
x["f"](x.&);
println("calling x[\"f\"] as x::f(x.&) (equivalent to the call above)");
x::f(x.&);
println("calling x[\"f\"] as x.f() (equivalent to the call above, x.& is implicitly passed as the first argument)");
x.f();
print("\n");
println("==============");
println("== Try-Else ==");
println("==============");
try { println("inside try block"); } else err { println("inside try-else block: " + err); }
try { error "some user defined error"; } else err { println("inside try-else block: " + err); }
try { let x = []; x[1]; } else err { println("inside try-else block: " + err); }
try { let x = []; x[1] = 123; } else err { println("inside try-else block: " + err); }
try { let x = map{}; x["foo"]; } else err { println("inside try-else block: " + err); }
try { let x = map{}; x["foo"] = 123; } else err { println("inside try-else block: " + err); }
try { let x = map{}; x::foo; } else err { println("inside try-else block: " + err); }
try { let x = map{}; x.foo; } else err { println("inside try-else block: " + err); }
print("\n");
println("=======================");
println("== Builtin Functions ==");
println("=======================");
# Lumpy ships with a number of useful builtin functions.
#
# For example, most numbers (including number literals) may call the builtin
# `is_integer` metafunction to test if the number is an integer.
println("NaN.is_integer() is " + repr(NaN.is_integer()));
println("Inf.is_integer() is " + repr(Inf.is_integer()));
println("(+123).is_integer() is " + repr(123.is_integer()));
println("(-123).is_integer() is " + repr(123.is_integer()));
println("123.5.is_integer() is " + repr(123.5.is_integer()));
print("\n");
# Another example, `math::sqrt`, returns the square root of an input number.
println("math::sqrt(25) is " + repr(math::sqrt(25)));
println("math::sqrt(2) is " + repr(math::sqrt(2)));
print("\n");
# The functions `print`, `println`, `dump`, `dumpln`, and `repr`, used
# extensively throughout this overview, are also Lumpy builtins!
dumpln(print); # print@builtin
dumpln(println); # println@builtin
dumpln(dump); # dump@builtin
dumpln(dumpln); # dumpln@builtin
dumpln(repr); # repr@builtin
# The behavior of each builtin function is described by the function's
# associated test under the `tests` directory.
print("\n");
println("==================");
println("== Example Code ==");
println("==================");
println("Example Merge Sort");
let sort = function(x) {
if x.count() <= 1 {
return x;
}
let mid = (x.count() / 2).trunc();
let lo = sort(x.slice(0, mid));
let hi = sort(x.slice(mid, x.count()));
let lo_index = 0;
let hi_index = 0;
let result = [];
for _ in x.count() {
if lo_index == lo.count() {
result.push(hi[hi_index]);
hi_index = hi_index + 1;
}
elif hi_index == hi.count() {
result.push(lo[lo_index]);
lo_index = lo_index + 1;
}
elif lo[lo_index] < hi[hi_index] {
result.push(lo[lo_index]);
lo_index = lo_index + 1;
}
else {
result.push(hi[hi_index]);
hi_index = hi_index + 1;
}
}
return result;
};
let vec = [6, 8, 3, 1, 7, 2, 4, 5, 9];
dumpln(sort);
println("unsorded vector is " + repr(vec));
println("sorted vector is " + repr(sort(vec)));
print("\n");
println("Example Fibonacci");
let fibonacci = function(x) {
if x == 0 {
return 0;
}
elif x == 1 {
return 1;
}
else {
return fibonacci(x - 1) + fibonacci(x - 2);
}
};
dumpln(fibonacci);
println("fibonacci(10) is " + repr(fibonacci(10)));
print("\n");
println("============================");
println("== Top-Level Error Traces ==");
println("============================");
let g = function() {
let f = function() {
error "oopsie";
};
f();
};
function() {
let h = function() {
g();
};
h();
}();