The history of programming languages evolution has involved moving away from how the machine represents programs (i.e. assembler) to how humans conceptualize them. Contemporary languages like Java are perhaps as abstract from the machine as is possible while still remaining general purpose. The next logical step in this progression are DSLs which by their nature are going to have some level of specifity to the application being constructed.
Language Oriented Programming (LOP) is concerned with giving users the mechanism to define DSLs or to extend existing ones. XMF is an open source programming language which supports the LOP paradigm. All aspects of XMF can be easily extended or redefined at run-time allowing the dynamic construction of domain specific languages (DSLs) which can be used either standalone or weaved into existing DSLs. The following example shows how program languages defined in XMF (Java, Lisp, PHP and XOCL) can be woven together to specify a program:
parserImport Languages::MicroJava;
parserImport XOCL;
parserImport Parser::BNF;
import LispOps;
context Root
@Operation count(S:Seq(Element)):Integer
S->size
end
context Root
@Java
class X {
int x ;
public X(int x) {
this.x = x;
}
public int test() {
Vector ints = this.descending(x);
Vector ascending = this.reverse(ints);
Vector facts = this.mapFact(ascending);
this.printCollection(facts);
}
with JOCL {
@Operation mapFact(s:Seq(Integer)):Integer
s->collect(n | self.fact(n))
end
}
with JOCL {
@Operation reverse(S:Seq(Element)):Seq(Element)
S->reverse
end
}
with JLisp {
(let ((Fact
(lambda (fact)
(lambda fact (n)
(if (eql n 0)
1
(mult n (fact (sub n 1))))))))
(Y Fact))
}
with JLisp {
(let ((descending
(lambda(descending)
(lambda descending(n)
(if (eql n 0)
()
`(,n . ,(descending (sub n 1))))))))
(Y descending))
}
with JPHP {
function printCollection($collection) {
for($i=0;$i<count($collection);$i++) {
echo $collection[$i]
}
}
}
}