ometa M { fact 0 -> 1, fact :n ?(n > 0) fact(n - 1):m -> (n * m) } M.match(5, "fact") ometa G { //Constructors Edge :pa :pb ?(pa.isNumber && pb.isNumber) -> {a: pa, b: pb, isEdge: true } //There should be a Vert, or have Graph check for isnumber on each? //should check types more Graph :v :e ?(v.isSequenceable && e.isSequenceable) -> {verts: v, edges: e, isGraph: true}, /* Cell :px :py :pz ?(px.isNumber && py.isNumber && pz.isNumber) -> {x: px, y: py, z: pz, isCell: true}, Cell :px :py :pz ?((!px.isNumber && py.isNumber && pz.isNumber)) -> {x: px, y: py, z: pz, isCell: true}, Euclidian Cell:a Cell:b -> (abs(a.x-b.x) + abs(a.y-b.y) + abs(a.z+b.z)), Neighbors Cell:a Cell:b Euclidian(a,b):e ?(e == 1) -> true Neighbors Cell:a Cell:b -> false, */ Test :x ?(x==0) Graph([1,2,3],[{a: 1, b: 2}, {a: 1, b: 3}]):g -> g, //Test :x ?(x==1) Cell(1,1,1):c -> c, //Test :x ?(x==2) Cell(1,1,1):a Cell(1,1,2):b Euclidian(a,b):c -> c, Test :other -> other } console.log('compiled') var r0 = G.match(0,'Test'); console.log(['Test0:',r0]) var r1 = G.match(1,'Test'); console.log(['Test1:',r1]) var r1 = G.match(2,'Test'); console.log(['Test2:',r1])