Artifact Content
Not logged in

Artifact 12b974146da199064d32689e2a25475a2e051659


     1  @@type = fun(x){
     2    if _isint(x): "int"
     3    else if _isstr(x): "str" 
     4    else if _isundefined(x): "undefined"
     5    else: "any"
     6  };
     7  
     8  def binop(a,b,c) {
     9    fun(x,y){@value(
    10      if( @type(x)=="undefined" || @type(y)=="undefined" ) then "undefined" else
    11        if( @type(x)==a && @type(y)==b ) then c else "error"
    12    )}
    13  };
    14  
    15  @type "+" = binop("int", "int", "int");
    16  @type "-" = binop("int", "int", "int");
    17  @type "<" = binop("int", "int", "int");
    18  @type ">" = binop("int", "int", "int");
    19  
    20  def mergeType(a,b) {
    21    if( a == "undefined" ): ( if(b=="undefined"):"error" else b  ) else ( a )
    22  };
    23  
    24  @type "if" = fun(c,t,e) {@value(
    25   if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error"
    26  )};
    27  
    28  def fib(x)
    29  {
    30  	if x<2 then 1 else fib(x-1) + fib(x-2)
    31  };
    32  
    33  print( @type(fib(10)) );