Artifact Content
Not logged in

Artifact b35cfd66e862f7bf189142d9927955d8905ac7b1


@@type = fun(x){
  if( _isint(x) ) { "int" }
  else { if( _isstr(x) ) { "str" }
  else { if( _isundefined(x) ) { "undefined" }
  else { "any" }}}
};

def binop(a,b,c) {
  fun(x,y){@value(
    if( @type(x)=="undefined" || @type(y)=="undefined" ) { "undefined" } else {
      if( @type(x)==a && @type(y)==b ) { c } else { "error" }
    }
  )}
};

@type "+" = binop("int", "int", "int");
@type "-" = binop("int", "int", "int");
@type "<" = binop("int", "int", "int");
@type ">" = binop("int", "int", "int");

def mergeType(a,b) {
  if( a == "undefined" ) { if(b=="undefined"){"error"}else{b} } else { a }
};

@type "if" = fun(c,t,e) {@value(
 if(@type(c)=="int" ) { mergeType(@type(t()), @type(e())) } else { "error" }
)};