5afe8e3f26 2010-11-13 kinaba: @@type = fun(x){ 3ae09b8cbf 2010-11-24 kinaba: if _isint(x): "int" 3ae09b8cbf 2010-11-24 kinaba: else if _isstr(x): "str" 3ae09b8cbf 2010-11-24 kinaba: else if _isundefined(x): "undefined" 3ae09b8cbf 2010-11-24 kinaba: else: "any" 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def binop(a,b,c) { f86026acb8 2010-11-21 kinaba: fun(x,y){@value( 3ae09b8cbf 2010-11-24 kinaba: if( @type(x)=="undefined" || @type(y)=="undefined" ) then "undefined" else 3ae09b8cbf 2010-11-24 kinaba: if( @type(x)==a && @type(y)==b ) then c else "error" 5afe8e3f26 2010-11-13 kinaba: )} 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: @type "+" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "-" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "<" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type ">" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def mergeType(a,b) { 3ae09b8cbf 2010-11-24 kinaba: if( a == "undefined" ): ( if(b=="undefined"):"error" else b ) else ( a ) f86026acb8 2010-11-21 kinaba: }; f86026acb8 2010-11-21 kinaba: f86026acb8 2010-11-21 kinaba: @type "if" = fun(c,t,e) {@value( 3ae09b8cbf 2010-11-24 kinaba: if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error" f86026acb8 2010-11-21 kinaba: )}; b993a8ad16 2010-11-24 kinaba: b993a8ad16 2010-11-24 kinaba: def fib(x) b993a8ad16 2010-11-24 kinaba: { b993a8ad16 2010-11-24 kinaba: if x<2 then 1 else fib(x-1) + fib(x-2) b993a8ad16 2010-11-24 kinaba: }; b993a8ad16 2010-11-24 kinaba: b993a8ad16 2010-11-24 kinaba: print( @type(fib(10)) );