Home

News: Language Oriented Programming with XMF

  1. Language Oriented Programming with XMF (19 messages)

    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]="" }="" end<="" re="">

    Threaded Messages (19)

  2. I'm very interested in this. Can you elaborate more on what this example does? Perhaps you could expand this to a fully-fledged article.
  3. Hello James - thanks for your comments. There is lots of XMF documentation in http://www.ceteva.com/XMF/ if you look in the "Programmers Guide" section the style is more or less that of self contained articles. We are planning to make available an article which gives an overview of this technology and its application. That article may or may not use this example. For the general motivation for this type of technology see the following brief Language Oriented Programming overview: http://www.ceteva.com/XMF/Getting%20Started/LOP/LOP.html. The version of this example on: http://www.ceteva.com/XMF/Snippets/Mixed/Mixed.html is color coded making it easier to see the different languages. Also at the bottom of that page is an exampe of running the program. Four languages have been defined using XMF - Java (Blue), Lisp (Green), PHP (Black) and XOCL (red). XOCL is XMF's default language but it is defined using exactly the same mechanisms as the other language mentioned. The definition for these languages can be found in the open source XMF system (and in some cases within the "Snippets" section of the XMF documentation). What is important is that the languages were defined without knowledge of each other. The outer language is in this case Java which includes a language escape construct "with X" where X is the name of any language grammar available within the system (the Java definition neither knows or cares). This enables other languages to be embedded within the lexical scope of Java. Since the different languages all desugar to the same language (XOCL) the program makes semantic sense and can be run. The factorial example here is trivial in function, but realistic in that XMF has been used to define languages that already exist. This is to be contrasted with dreamt up domain specific languages that can be tailored to a system's capability. Note that different languages can be used to collectively specify the same system without the weaving shown here. That is, it is possible to have Java exclusively within its own file, PHP in another etc. without any constructs that are foreign to those languages. Hope that helps.
  4. Anyone remember embedded sql?[ Go to top ]

    Considering what a mess that was, I am quite astonished, anyone would come up with such an idea as a general programming paradigm for n languages. COS seems to be a better acronym: Chaos Oriented Programming.
  5. Re: Anyone remember embedded sql?[ Go to top ]

    In hindsight the example given might not be the best since it has given rise to a misconception among a few that: a) this was a proposal for a new language that mixed Java/Lisp/PHP etc; or b) that the proposal was to generally start mixing existing programming languages in this way. Neither of these are the case. The principle idea behind DSLs and LOP is to give practitioners languages that are most appropriate to their activities. As an example, within a financial system, the GUI designers might use a forms based GUI language with constructs relating to financial relevant fields. The domain experts might use a special language for describing just financial rules such as derivative exchanges. Both of these languages would be used to describe the same systems but partitioned from each other. The languages could also be independent of implementation technology and an MDA like approach could be used to target multiple technology implementations. XMF is intended to support the description and usage of these types languages. XMF is not intended for programmers to start coding in hybrid Java, PHP, Lisp etc. languages (although that is possible, but not realistic). The example was intended to demonstrate how XMF is expressive enough to describe existing languages and for programs written using mixed languages to be collectively meaningful.
  6. XMF License and sources[ Go to top ]

    I couldn't find any licensing informations on http://www.ceteva.com. What about sources? Besides that, it's a great approach. I will be reading everything very soon.
  7. Re: XMF License and sources[ Go to top ]

    Pedro - XMF is Open Source under the Eclipse Project License (EPL), downloadable from: http://www.ceteva.com/xmf.html.
  8. Re: Anyone remember embedded sql?[ Go to top ]

    The principle idea behind DSLs and LOP is to give practitioners languages that are most appropriate to their activities. As an example, within a financial system, the GUI designers might use a forms based GUI language with constructs relating to financial relevant fields. The domain experts might use a special language for describing just financial rules such as derivative exchanges. Both of these languages would be used to describe the same systems but partitioned from each other.
    In consequence that would mean that the DSL would evolve in very much the same way than todays domain specific libraries in the various programming languages we are using today. However they would be far less constrained in what can change about them (in particular the grammar of course). I have seen "domain specific languages" that make sense, like the typical 4GLs used for scientific analysis. But I can hardly believe, that there is much benefit in mixing such languages. In particular, I don't believe that it can be done without breaking the abstraction to the underlying technology that waves the various DSL artifacts together.
  9. The principle idea behind DSLs and LOP is to give practitioners languages that are most appropriate to their activities.
    Why bother with a new domain specific language when, almost always, 90% of the benefit can be achieved much more quickly, easily, comprehendably, maintainably by having a new domain specific library? On the one hand we (usually) have a DSL that means that a small number of domain specific applications are a little bit shorter and easier for the author to understand. On the other hand there's little tool support, the DSL usually grows incrementally into a mess, and it is difficult to to recruit and train people in the use of your language. Please indicate the balance between those two "hands" :)
  10. Tom - Good question. There is a fundamental difference between a library and a DSL. A DSL is much more like a framework than a library (see the article at http://www.ceteva.com/XMF/Programmers%20Guide/DSL/DSL.html). A framework differs from a library in that there is an inversion of control. A DSL is a specialization of the idea of a framework where the services are represented in data. The essence of a DSL is the definition of a framework (or DSL engine) and the data that represents the 'programs' in the DSL. Since the framework is defined once and reused many times, it rapidly stabilizes and becomes reliable. Unlike a library, a DSL/framework is a closed world whose quality is easy to control. Often a library can only be controlled through type definitions on the interfaces which is much weaker. Although DSLs and LOP are often described in terms of concrete syntax, the essential engineering leverage is at the abstract syntax level where the ability to impose design and implementation control throughout large projects becomes important. A language driven approach to system development is a technique that can be badly applied in the same way as more traditional development methods. A system that has been well engineered using language engines for appropriate components is easier to maintain than the equivalent system all written in one general programming language: it is easier to understand and is easier to control.
  11. In addition, by having the level of control DSLs and frameworks enable it is possible to perform activities that would not be possible with libraries. For example it is possible to translate programs written in DSLs into multiple implementations since the language is a closed world and can be entirely accounted for in a translation. This type of MDA translation can be extremely powerful in abstracting from technology specific implementations.
  12. Congratulations on reaching a new level of obscurity! As one other commenter said, why not use a domain specific library? In combination with good object-oriented design, it is practically like using a domain-specific language. Is the problem that XMF solves bigger than the one it introduces?
  13. Erik - I refer you to the answer I gave a moment ago. Namely that DSLs are very different from libraries because they offer a greater degree of control with what can be represented. They can (if applied correctly) significantly contribute to the quality of the artifacts being engineered. -http://www.theserverside.com/news/thread.tss?thread_id=48655#248702
  14. Congratulations on reaching a new level of obscurity!
    :) I think the idea was that XMF is flexible enough to implement custom language with any of these syntaxes, NOT that you should start programming your enterprise apps using lisp. (though i must say that the ubiquitous "Lightweight AJAX POJO Framework" but implemented in Prolog would be interesting to see). Personally i feel that majority of frameworks introduced in TSS are waste of time, but i think this XMF and language oriented programming are actually quite interesting. Also, JetBrains has had something related cooking for several years, google for 'Meta Programming System'. /Henri Karapuu
  15. I personally think this is an interesting enterprise and path to explore for the software engineers. And I am starting from the following. Think of your high-technology Java product. For its development, besides Java you are quite probably using many other languages: * Spring: application context (XML -like) language (files) (dependency injection) * AOP: cross-cutting concerns and aspects language * Java Annotations: isn't this a kind of a "language within the language" * Persistence annotations (either Java or Spring) represents the Oject Relational Mapping (ORM) language. * SQL Data Definition Language if you a have a relational schema - although it may result as an artifact of an ORM (eg. Hibernate) * Ant XML file - although is expressed in XML is fundamental a language specialised in expressing target dependencies and construction receipts. Alternatives: Maven with POMs, etc. * Unit and System testing. It can be argued that somehow the Unit tests use their own language (more so when using a particular mocking technique) * System and integration tests can be frequently written in a scripting language like Shell scripts, perl, PHP, tcl. In brief, the production of software requires employment of multiple language and formalisms. DSL's are quite adequate when your focus is on a particular application domain like network or system management, intrusion detection, etc., etc. And the challenge here appears to be the natural and pragmatic integration of multiple languages and formalisms needed to go through all stages, phases and iterations of product development. The better integrated these stages, phases and steps, the more efficient and intelligent algorithms can unify and control all these components. A GLUE, underlying language like XMF is a very interesting proposition. An MDA (Model Driven Architecture) is also quite compatible with a XMF -like approach. And higher level abstraction languages (that I guess can be easily constructed and expressed with XMF) may be another promising path to explore.
  16. DSLs[ Go to top ]

    I'm not sold on DSLs but I see potential value in my current field because of the high level of complexity of the business domain. I think that part of the reason that we have so many problems keeping up with our work is that we are spending too much time translating these complex requirements into executable code. I agree that you can accomplish these goals with a library but the problem is that this takes a lot of expertise. OO approaches are fairly well suited but it takes a lot of time an expertise to understand how to apply OO effectively and no one else will be able to understand what the code does. I'm absolutely ready to dismiss something if I feel it's not worth my time and this may be one of those things. But I think we should try not to dismiss ideas or tools solely because they are foreign to us.
  17. Re: DSLs[ Go to top ]

    Hi James, thanks for your thoughts. DSLs are not necessarily whole new languages, so it is possible to take an out of the box OO language and add domain constructs. As an example of this, XMF's default language XCore (which is OO) has been augmented over the years with additional constructs for various activities. One example construct is "Constraint" which supports the specification of constraints and their checking over the state of instances. Orientating existing languages to domain activities, potentially with one or a few constructs, is much less expensive than designing and building whole new languages from scratch.
  18. Re: DSLs[ Go to top ]

    Hi James, thanks for your thoughts.

    DSLs are not necessarily whole new languages, so it is possible to take an out of the box OO language and add domain constructs. As an example of this, XMF's default language XCore (which is OO) has been augmented over the years with additional constructs for various activities. One example construct is "Constraint" which supports the specification of constraints and their checking over the state of instances.

    Orientating existing languages to domain activities, potentially with one or a few constructs, is much less expensive than designing and building whole new languages from scratch.
    I got the feeling that is what XMF provides which is why my interest was piqued. I haven't had time to look at this but it's on my list of things to learn more about.
  19. I think Jetbrains has a Language Oriented Programming package called MPS: http://www.jetbrains.com/mps/ I believe there's even a full blown product made with it: http://www.sergeydmitriev.com/mps/blog/ Has anyone an idea how does XMF compare to MPS? Thank you, Demetrios.
  20. I believe that MPS is an IDE based application. You would use the MPS IDE to incrementally build up the definition of a language which will deliver a tool for working with the language. In that sense MPS is an IDE or workbench. XMF is a more conventional programming language. It can be used as a very high-level language in the same sense as Ruby, Python or Scheme. The XMF language is not tightly coupled to any tooling such as an IDE (although an Eclipse IDE is planned for XMF later this year). You write language definitions in XMF as programs. Once the programs are compiled and loaded, the languages are then available and can be used as part of other programs, and so on. Another difference is that XMF can be embedded in Java applications. I'm not sure that is true of MPS. When you load XMF programs (including language definitions) you can save an image. You can start a new VM from within a Java program and load the same image. This allows Java apps to run XMF applications. -- Tony