060f267779 2010-11-20 kinaba: @macro twice(x) { x; x }; 060f267779 2010-11-20 kinaba: @macro max(x,y) { 060f267779 2010-11-20 kinaba: var _x = x; # no hygenic macro btw.... 060f267779 2010-11-20 kinaba: var _y = y; # no hygenic macro btw.... 060f267779 2010-11-20 kinaba: if(_x<_y){_y}else{_x} 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: def maxNormal(x,y) { 060f267779 2010-11-20 kinaba: if(x<y){y}else{x} 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: @macro maxBad(x,y) { 060f267779 2010-11-20 kinaba: if(x<y){y}else{x} 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: @macro LetItBe(x, y) { 060f267779 2010-11-20 kinaba: let it = x in y 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: @macro pow10(x) { 060f267779 2010-11-20 kinaba: @v( 060f267779 2010-11-20 kinaba: def pow(x, n) { 060f267779 2010-11-20 kinaba: if( n == 1 ) { x } 060f267779 2010-11-20 kinaba: else { 060f267779 2010-11-20 kinaba: @macro( @v(x) * @v(pow(x,n-1)) ) 060f267779 2010-11-20 kinaba: } 060f267779 2010-11-20 kinaba: } 060f267779 2010-11-20 kinaba: in 060f267779 2010-11-20 kinaba: pow(@macro(x),10) 060f267779 2010-11-20 kinaba: ) 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: def printAndReturn(x) 060f267779 2010-11-20 kinaba: { 060f267779 2010-11-20 kinaba: print(x); 060f267779 2010-11-20 kinaba: x 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: def main() 060f267779 2010-11-20 kinaba: { 060f267779 2010-11-20 kinaba: twice( print("foo") ); 060f267779 2010-11-20 kinaba: print("--------------"); 060f267779 2010-11-20 kinaba: print(max(printAndReturn(100),printAndReturn(200))); 060f267779 2010-11-20 kinaba: print("--------------"); 060f267779 2010-11-20 kinaba: print(maxNormal(printAndReturn(100),printAndReturn(200))); 060f267779 2010-11-20 kinaba: print("--------------"); 060f267779 2010-11-20 kinaba: print(maxBad(printAndReturn(100),printAndReturn(200))); 060f267779 2010-11-20 kinaba: print("--------------"); 060f267779 2010-11-20 kinaba: print( LetItBe( 1+2+3, it*it ) ); 060f267779 2010-11-20 kinaba: print("--------------"); 060f267779 2010-11-20 kinaba: print(pow10(2)); 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: main()