Join the M revolution—Get your tools | Opensource.com
Join the M revolution—Get your tools
The M programming language is also known as MUMPS. Which stands for Massachusetts General Hospital Utility Multi-Programming System. Read my earlier post introducing the multi-user, strongly imperative language designed to manipulate and control massive databases. Then get started using it with this tutorial.
Two main software environments are available today for programming in M:
You can download an evaluation version of Intersystems Caché, but because FIS GT.M is free and open source, we will use it here as the reference system for this tutorial.
The M language has a well defined set of standards:
We will stick to the M-standard in the exercises of this tutorial, therefore the source code examples should work in both GT.M and Caché environments.
Let's focus now on installing GT.M and getting it to work in your favorite Linux installation.
Step 1: Download and install GT.M
Download and install GT.M:
$ wget http://download.sourceforge.net/project/fis-gtm/GT.M%20Installer/v0.11/gtminstall
$ chmod +x gtminstall
$ sudo ./gtminstall --utf8 default
Work is in progress to create Debian packages for GT.M (debian-med fis-gtm), and they should be available soon. In the meantime, the instructions above are the most straightforward way to install GT.M in your Linux environment. Note that this installation will use easy defaults. Such an environment will be good for trying out GT.M and for running through the exercises of this tutorial, but it may not be good enough for a production system. Consider this installation a safe sandbox for learning M.
The executables of the installation will, by default, go to one of the following directories (depending on whether you are in a 32-bit or 64-bit architecture):
Now we set up the environment variables for GT.M by sourcing the gtmprofile file.
From your shell, do the following:
$ source /usr/lib/fis-gtm/V5.5-000_x86/gtmprofile
You will see output similar to:
%GDE-I-GDUSEDEFS, Using defaults for Global Directory
%GDE-I-EXECOM, Executing command file /usr/lib/fis-gtm/V5.5-000_x86_64/gdedefaults
%GDE-I-VERIFY, Verification OK
%GDE-I-GDCREATE, Creating Global Directory file
Created file /home/ibanez/.fis-gtm/V5.5-000_x86_64/g/gtm.dat
%GTM-I-JNLCREATE, Journal file /home/ibanez/.fis-gtm/V5.5-000_x86_64/g/gtm.mjl created for region DEFAULT with BEFORE_IMAGES
%GTM-I-JNLSTATE, Journaling state for region DEFAULT is now ON
For the long term, it is convenient to do this from the initialization file of your favorite shell. For example, in bash, add the following lines to your $HOME/.bashrc file:
# Set up GT.M environment.
This adds a set of GT.M-related variables to your environment, and also adds the GT.M executables to your PATH. If you are curious, you may want to take a look at those changes by doing the following in the prompt of your bash shell:
$ env | grep gtm
Now you can run GT.M for the first time by simply typing gtm at the shell prompt.
This should open the GT.M prompt:
At this point you can type a couple of verification commands. For example:
GT.M V5.5-000 Linux x86
The “intrinsic special variable” $zversion returns the version of the installed M environment. The halt command stops the gtm interpreter and returns control to the operating system, so you will be back at your shell's prompt.
The initialization process creates a local installation in your home directory under:
with the subdirectories:
$HOME/.fis-gtm/V5.5-000_x86 (if in a 32bits architecture)
$HOME/.fis-gtm/V5.5-000_x86_64 (if in a 64bits architecture)
As we write code examples, these are the directories where the code will go.
This is a good point to note that M/MUMPS is a combination of a programming language and a database (as was kindly pointed out by one of the first commenters to our previous post). We will try to be more explicit going forwards when we are referring to the language versus when we are referring to the database.
Step 2: Testing the installation
We can now write a “hello world” program.
First, set the path to your favorite editor in the “EDITOR” environment variable of your shell. For example in bash:
Then from the same shell, invoke gtm, and at the prompt, request to edit the “Hello.m” file:
This should open the editor program that you just set up in the EDITOR environment variable, and now you can type in it the following M code:
MYLABEL ; This is a comment
WRITE !,”Hello World”
Note that the second two lines leave one blank space in the first column, while the first line (containing a label) starts in the first column.
Then save the file and quit the editor. Once back at the gtm prompt, type:
and execute the program by using the DO command:
Let's now edit the program again by typing:
and once in the editor, let's insert another line:
MYLABEL ; This is a comment
WRITE !,”Hello World”
Then save the file and link it again with the command:
It is important to call ZLINK every time that your modify the source code, since it will recompile it and will replace the previous code in the current environment. Now you can execute the new version with:
The $HOROLOG special variable returns the date and time as a string value specifying the number of days since December 31, 1840 and the number of seconds since midnight of the current day. (Read why that date was chosen.)
Step 3: Looking under the hood
You may find it interesting to see where the source code and compiled versions of your routines are going. Take a look at the directories:
where you will find the files:
Many thanks to K.S. Bhaskar (Development Director at Fidelity National Information Services, Inc.) for his guidance on fis-gtm and for providing the large majority of the materials presented in this tutorial. All errors that may have slipped above, of course, are mine alone.
The complete reference to the M language is available at:
The pocket guide to MUMPS is available at: