Saturday, February 14, 2009 2:05 AM
The M Programming Language – Part 0 – Intellipad, MrEPL, VS2008 project support and Excel integration
As promised in my previous introductory post on “Oslo” and “M”, I’ll be running a new language-focused blog series, this time about the modeling language “M”. In this first installment, our goal is to become intimately familiar with the “M” programming environment, so we can start to study the language without any hurdles.
If you haven’t done already, go and download the Oslo SDK January 2009 CTP. Also take a look at the Release Notes. What we’ll be focusing on in this post is the higher-level tool support provided in the SDK. We’ll skip the command-line tools for now (m, mx, etc) – for more info, see my introductory post on “Oslo” and “M” – but focus on the following instead:
· Microsoft Visual Studio® integration: edit and build "M" in Visual Studio 2008
· “Intellipad”: a text editor with "M" language services
· "M" Add-in for Microsoft Excel® 2007: imports and exports "M" into and from Microsoft Excel 2007
In the first couple of subsequent posts I’ll try to stay within the boundaries of those two. At a later stage, we’ll dive a bit deeper again and focus on other SDK tools.
This should be your new Notepad. It’s a modern, extensible and highly command-driven text editor ideal for developers. You’ll find it in your Start Menu, under Microsoft Oslo SDK, Tools. It looks plain simple in its innocent form (i.e. no special modes selected):
What do you need to know about it? First, there’s a Help menu. Use it to find out about all the shortcuts: Help, Commands (Alt-F1):
Notice the concept of “Mini Buffer” at the top. Basically, it’s a simple command-line that can be entered by pressing CTRL+/. Notice: for non-QWERTY keyboards, this means: CTRL plus the key that has ‘/’ on it (without SHIFT or so if it appears in the top position, as is the case on some AZERTY keyboards). Enter Mini Buffer Command mode and you’ll see this:
Let’s enter a command like Zoom(2.0); and see what happens:
Handy for demos. There are alternative ways to zoom, CTRL++ and CTRL+-.
Other things you need to know about Intellipad? Not much, except for the selection of modes in the top-right corner. For example, here I switched to M Mode (actually, modes are another extensibility point of Intellipad, something I might talk about later as well) and types nonsense:
Notice how mode-specific menus appear upon switching to another mode.
(For the interested, search the Oslo SDK folder for .py Python files and get an idea about how scripting is used to make Intellipad extensible…)
Read-Eval-Print-Loops are great for interactive development, experimentation, testing, debugging, etc. The languages used in modeling are very well-suited to benefit from such a REPL tool, so the Oslo SDK comes with such a beast integrated in Intellipad. You can find the binaries of MrEPL under %ProgramFiles%\Microsoft Oslo SDK 1.0\Bin\Intellipad\Samples\Microsoft.Intellipad.Scripting.M. So, how to get it started within Intellipad? What you’re looking at is a kind of add-in model, so we should launch ipad.exe in such a way that it known to find the MrEPL “add-in”. The way this works is by loading something called a catalog, which is defined in XAML (once more). You’ll find a file called ipad-vs-samples.xaml under the install location of the Oslo SDK, which contains stuff like this:
<!-- Copyright (c) Microsoft Corporation
All rights reserved -->
<mi:IntellipadCatalogSource SubDirectoriesOnly='true' DirectoryPath='Components' RelativeCacheFilePath='ipad\components.catalog' />
<mi:IntellipadCatalogSource SubDirectoriesOnly='true' DirectoryPath='Samples' RelativeCacheFilePath='ipad\samples.catalog' />
<mi:IntellipadCatalogSource DirectoryPath='Settings' RelativeCacheFilePath='ipad\settings.catalog'/>
<mi:IntellipadCatalogSource DirectoryPath='Settings\VisualStudio' RelativeCacheFilePath='ipad\settings-visualstudio.catalog'/>
The second IntellipadCatalogSource points at the Samples folder, where it can find the MrEPL sample. Remaining question is how to tell ipad to use this file to populate catalogs and load the referenced add-ins. Actually, you didn’t need to know anything about this since there’s a shortcut in the Start Menu that does precisely this:
Alright, let’s launch it and see we can invoke MrEPL by going to the mini-buffer (CTRL+/) and typing SetMode(‘MScriptMode’):
and guess what, there we are, interactive and well:
This will become our playground quite a bit when exploring the language features of M, so you better start to get used to it :-).
Visual Studio 2008 support
Intellipad is great, but sometimes it just makes sense to get the support of a project system, MSBuild, source control, etc from a rich IDE like Visual Studio. So, not unsurprisingly, the Oslo SDK comes with support for Visual Studio integration out of the box. After installation of the SDK, go to Visual Studio and create a new project. You should see a template for “Oslo”:
Integration with Visual Studio is rather limited at the moment but all the essentials are in. “M” projects contain, not too surprisingly, .m files:
Mistakes produce errors, and building the project is supported:
For the curious, the Add Reference dialog allows you to select .mx files, “M” image files (see my previous post for information about those). And if you’re curious how the build system works, take a look at the targets file in %ProgramFiles%\MSBuild\Microsoft\M\v1.0. Building a project produces both a .sql file and a .mx file:
Deployment of the model definition is a manual step, but more about that later (or, again, in my previous post).
Excel 2007 integration
Finally, as M is about data, and most information workers use Excel as a data front-end, M offers integration with Excel too. To install this, go to the Start Menu, Microsoft Oslo SDK, Tools and run the M-addin installer:
You’ll see the Office Customization installer pop up; just accept the customization to be installed:
Finally, Excel will have been extended with ribbon options under the Data tab, that allow to import and export data from and to M:
For example, importing my (empty) MySuperModels project created before, produces the following table:
More about that later.
If you were able to complete all of the steps above, you’re ready to get started with our M blog series. Next time, we’ll start by looking at M’s type system and play more with MrEPL.Del.icio.us
| Digg It
Filed under: Oslo, M