ba11f1d551 2010-11-23 kinaba: @macro twice = fun(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.... 3ae09b8cbf 2010-11-24 kinaba: if(_x<_y)then _y else _x 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: def maxNormal(x,y) { 3ae09b8cbf 2010-11-24 kinaba: if(x<y) 3ae09b8cbf 2010-11-24 kinaba: then: y 3ae09b8cbf 2010-11-24 kinaba: else: x 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: @macro maxBad(x,y) { 3ae09b8cbf 2010-11-24 kinaba: if x<y: y else: x 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: 435fa085ec 2010-11-21 kinaba: @macro LetItBe(x, y) { let it = x in y }; 060f267779 2010-11-20 kinaba: 060f267779 2010-11-20 kinaba: @macro pow10(x) { 435fa085ec 2010-11-21 kinaba: @value( ba11f1d551 2010-11-23 kinaba: def pow(y, n) { 3ae09b8cbf 2010-11-24 kinaba: if( n == 1 ) then y 3ae09b8cbf 2010-11-24 kinaba: else ba11f1d551 2010-11-23 kinaba: @macro( @value(y) * @value(pow(y,n-1)) ) ba11f1d551 2010-11-23 kinaba: } ba11f1d551 2010-11-23 kinaba: in ba11f1d551 2010-11-23 kinaba: pow(@macro(x+1),10) ba11f1d551 2010-11-23 kinaba: ) ba11f1d551 2010-11-23 kinaba: }; ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: @macro pow10Hard(x) { ba11f1d551 2010-11-23 kinaba: @value( 060f267779 2010-11-20 kinaba: def pow(x, n) { 3ae09b8cbf 2010-11-24 kinaba: if( n == 1 ) then x 3ae09b8cbf 2010-11-24 kinaba: else 435fa085ec 2010-11-21 kinaba: @macro( @value(x) * @value(pow(x,n-1)) ) 060f267779 2010-11-20 kinaba: } 060f267779 2010-11-20 kinaba: in ba11f1d551 2010-11-23 kinaba: pow(@macro(x+1),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: 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("--------------"); ba11f1d551 2010-11-23 kinaba: print(pow10(1)); 060f267779 2010-11-20 kinaba: print(pow10(2)); ba11f1d551 2010-11-23 kinaba: print("--------------"); ba11f1d551 2010-11-23 kinaba: print(pow10Hard(1)); ba11f1d551 2010-11-23 kinaba: print(pow10Hard(2)); ba11f1d551 2010-11-23 kinaba: }; ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: main(); ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: @macro foo(y) ba11f1d551 2010-11-23 kinaba: { ba11f1d551 2010-11-23 kinaba: fun(y){y}(300) ba11f1d551 2010-11-23 kinaba: # let y = 300 in y 060f267779 2010-11-20 kinaba: }; 060f267779 2010-11-20 kinaba: ba11f1d551 2010-11-23 kinaba: print("--------------"); ba11f1d551 2010-11-23 kinaba: print(foo(200));