VASYA is loosely based on JavaScript

main VASYA features are

  • dynamic typing (types includes functions, numbers, strings and 2d vectors);
  • nested functions;
  • functions with variable number of arguments;
  • closures;
  • lambdas;
  • objects with prototype-based inheritance.

declaring local variables

local name[ = value];

declaring local functions

local name(arglist) = { body };
or
function name (arglist) { body }

objects

local obj = { json };

inheritance

obj.prototype = baseObject;

vectors

`0 1`

type conversion

(string)0.42
(number)"42"

Y combinator

// The Y combinator, applied to the factorial function

function factorial (proc) {  
  return function (n) { return n<=1 ? 1 : n*proc(n-1); };  
}  

function Y (outer) {  
  function inner (proc) {  
    function xapply (arg) {  
      return proc(proc)(arg);  
    }  
    return outer(xapply);  
  }  
  return inner(inner);  
}  

print("5! is "+Y(factorial)(5));

objects

(function () { print("this.print=", this.print); })();
local obj = {  
  field = 42;  
  method: function () { print("field=", this.field); }  
};  
print("obj: ", obj);  
print("field: ", obj.field);  
print("no_field: ", obj.no_field);  
obj.method();  

local o2 = {  
  prototype = obj;  
};  
write("must be 42: "); o2.method();  
o2.field = 666;  
write("must be 666: "); o2.method();  
write("must be 42: "); obj.method();

type coercion

typeof("5"+2) == "string"
typeof("5"+2) == "string"  
typeof(2+"5") == "string"  
typeof(2+"a") == "string"  
typeof(2+(number)"5") == "number"  
typeof(`1 2`+`3 4`) == "vector"