Differences From Artifact [977cd2f997805f91]:
- File
sample/macro.pmy
- 2010-11-23 18:28:47 - part of checkin [ba11f1d551] on branch trunk - fixed the macro scoping rules concerning non-macro let (user: kinaba) [annotate]
To Artifact [b31646ec7576a8a6]:
- File
sample/macro.pmy
- 2010-11-24 12:14:00 - part of checkin [3ae09b8cbf] on branch trunk - changed if-then-else syntax (user: kinaba) [annotate]
1 @macro twice = fun(x) { x; x }; 1 @macro twice = fun(x) { x; x };
2 @macro max(x,y) { 2 @macro max(x,y) {
3 var _x = x; # no hygenic macro btw.... 3 var _x = x; # no hygenic macro btw....
4 var _y = y; # no hygenic macro btw.... 4 var _y = y; # no hygenic macro btw....
5 if(_x<_y){_y}else{_x} | 5 if(_x<_y)then _y else _x
6 }; 6 };
7 def maxNormal(x,y) { 7 def maxNormal(x,y) {
8 if(x<y){y}else{x} | 8 if(x<y)
> 9 then: y
> 10 else: x
9 }; 11 };
10 @macro maxBad(x,y) { 12 @macro maxBad(x,y) {
11 if(x<y){y}else{x} | 13 if x<y: y else: x
12 }; 14 };
13 15
14 @macro LetItBe(x, y) { let it = x in y }; 16 @macro LetItBe(x, y) { let it = x in y };
15 17
16 @macro pow10(x) { 18 @macro pow10(x) {
17 @value( 19 @value(
18 def pow(y, n) { 20 def pow(y, n) {
19 if( n == 1 ) { y } | 21 if( n == 1 ) then y
20 else { | 22 else
21 @macro( @value(y) * @value(pow(y,n-1)) ) 23 @macro( @value(y) * @value(pow(y,n-1)) )
22 } <
23 } 24 }
24 in 25 in
25 pow(@macro(x+1),10) 26 pow(@macro(x+1),10)
26 ) 27 )
27 }; 28 };
28 29
29 @macro pow10Hard(x) { 30 @macro pow10Hard(x) {
30 @value( 31 @value(
31 def pow(x, n) { 32 def pow(x, n) {
32 if( n == 1 ) { x } | 33 if( n == 1 ) then x
33 else { | 34 else
34 @macro( @value(x) * @value(pow(x,n-1)) ) 35 @macro( @value(x) * @value(pow(x,n-1)) )
35 } <
36 } 36 }
37 in 37 in
38 pow(@macro(x+1),10) 38 pow(@macro(x+1),10)
39 ) 39 )
40 }; 40 };
41 41
42 def printAndReturn(x) 42 def printAndReturn(x)