Intervals in MPS

Language of mathematics contains a lot of domain specific constructs. Almost every part of mathematics has its own domain specific “extensions”. So it’s a good idea to borrow from there. In MPS we have a special base language extension that contains some mathematical notation. In this post we will consider one of such notations that we borrowed from mathematics.

We quite often write code that checks whether a value lies in a specific range. This is especially widespread in a code working with graphics. We might write something like this:

This piece of code checks whether a point lies inside a rectangle. Quite boring, isn’t it? In our jetbrains.mps.baseLanguage.math language we have support for intervals. Instead of the code above, you can write this:

As you can see it is shorter and much easier to read. Intervals, in the language can be open or closed. For example you can write this:

They can even contain infinities:

This language feature will be available in MPS 1.0. In addition to the intervals MPS will provide other mathematical notations, for example sums. We will write about them in one of the following posts.

Posted by Konstantin Solomatov, Lead MPS developer

Comments below can no longer be edited.

3 Responses to Intervals in MPS

  1. Avatar

    Joseph says:

    March 31, 2009

    This looks very nice.
    I wish such syntax where available in the smart IntelliJ editor (that cell based editor looks horrible and complicated for me 🙁 – I don’t think domain experts will use it 🙁 ).

    Please keep posting more often about MPS (like it’s happening lately with the IDEA blog).

  2. Avatar

    Konstantin Solomatov says:

    April 1, 2009

    2Joseph Have you tried our editor? Why do you think it is horrible?

  3. Avatar

    Joseph says:

    April 3, 2009

    > Have you tried our editor?
    Of course I did.

    > Why do you think it is horrible?
    I said that it is *for me* :).

    I like the idea of MPS very much – from the first moment I’ve read the initial article about it a few years ago.

    The problem (for me) is that MPS as a tool looks and behaves very complicated and non-intuitive at all – for me it’s the total opposite of what IntelliJ is (the most intuitive IDE existing right now).

    And now if this is extremely complicated for me as a developer do you think a domain expert would manage to use it? I don’t think so.

    Reading the initial article about MPS I thought that MPS as a tool would allow to “generate” something like your dead product Fabrique – a sort of environment with more DSLs to solve a concrete problem. Each DSL would have it’s own view and editors (like Fabrique had), but these “editors” would be different from DSL to DSL. E.g. in the case of Fabrique, the Domain Model was edited with a ER Diagram Editor, the View with a WYSIWYG, etc.

Discover more