Artifact b31646ec7576a8a64315253973b7157843742e22
1 @macro twice = fun(x) { x; x };
2 @macro max(x,y) {
3 var _x = x; # no hygenic macro btw....
4 var _y = y; # no hygenic macro btw....
5 if(_x<_y)then _y else _x
6 };
7 def maxNormal(x,y) {
8 if(x<y)
9 then: y
10 else: x
11 };
12 @macro maxBad(x,y) {
13 if x<y: y else: x
14 };
15
16 @macro LetItBe(x, y) { let it = x in y };
17
18 @macro pow10(x) {
19 @value(
20 def pow(y, n) {
21 if( n == 1 ) then y
22 else
23 @macro( @value(y) * @value(pow(y,n-1)) )
24 }
25 in
26 pow(@macro(x+1),10)
27 )
28 };
29
30 @macro pow10Hard(x) {
31 @value(
32 def pow(x, n) {
33 if( n == 1 ) then x
34 else
35 @macro( @value(x) * @value(pow(x,n-1)) )
36 }
37 in
38 pow(@macro(x+1),10)
39 )
40 };
41
42 def printAndReturn(x)
43 {
44 print(x);
45 x
46 };
47
48 def main()
49 {
50 twice( print("foo") );
51 print("--------------");
52 print(max(printAndReturn(100),printAndReturn(200)));
53 print("--------------");
54 print(maxNormal(printAndReturn(100),printAndReturn(200)));
55 print("--------------");
56 print(maxBad(printAndReturn(100),printAndReturn(200)));
57 print("--------------");
58 print( LetItBe( 1+2+3, it*it ) );
59 print("--------------");
60 print(pow10(1));
61 print(pow10(2));
62 print("--------------");
63 print(pow10Hard(1));
64 print(pow10Hard(2));
65 };
66
67 main();
68
69 @macro foo(y)
70 {
71 fun(y){y}(300)
72 # let y = 300 in y
73 };
74
75 print("--------------");
76 print(foo(200));