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

image description