Tuples Support in the MPS Base Language
Many functional and dynamic languages have “tuples” in their syntax. Tuple is a sequence of a fixed length. For example, pair, triple and quadruple are tuples. They are very useful when you have algorithms operating on entities which have two, three or more parts and you don’t want to create devoted classes for them, or if you want to return multiple instances from a method.
Let’s take a closer look at how tuples are implemented in MPS.
We have a tuple type. Here is a pair of String and int:
We have a special syntax for tuple construction: we added a new type of literal to the base language:
Each element of a tuple has a name by which it can be accessed:
Tuples are immutable, so you can only create new tuples but can’t change the existing ones. If two tuples contain same element types but different names they are compatible. I.e. you can write:
It took us only about half a day to implement such a cool features in MPS, so it isn’t really hard to do. This feature is going to be available in MPS Beta 2.
Posted by Konstantin Solomatov, Lead MPS developer
Subscribe to Blog updates
The Early Access Program for MPS 2021.3 is open
Our release of MPS 2021.3 will be delayed until next year. That said, we can’t finish the year without giving you a glimpse of what you can look forward to. DOWNLOAD MPS 2021.3 EAP Experimental Kotlin language support An experimental Kotlin implementation is now bundled with MPS. While it supports m…
Feature Freeze for MPS 2021.1
Today we’re rolling out the last build in the Early Access Program for MPS 2021.1, and these are the last few features that will be included in the release. Try them out. Zoom in and Zoom out The font size can be quickly adjusted in the currently open editor window by holding Control/Command and rol…
MPS 2021.1 EAP3 is now ready for you to try
We are getting ready for the major release of MPS 2021.1, and the Early Access Program (EAP) is our way of sharing with you the new functionality that we have been working on in recent months. Here are the new features we’ve implemented in this version. Model viewer in diff dialog The MPS model view…
Early Access Program of MPS 2021.1 is open
The Early Access Program is an important part of our product development process for identifying critical issues with the new release features. If you encounter any problems, please report them to our issue tracker. Check out the new functionality that we have prepared for you. Improved access to $L…