mumps-demo/README.md

329 lines
10 KiB
Markdown
Raw Permalink Normal View History

2019-09-25 10:26:47 -04:00
# MUMPS Examples
2019-09-23 11:33:02 -04:00
2019-09-23 12:13:32 -04:00
**MUMPS** ("Massachusetts General Hospital Utility Multi-Programming System"), or **M**, is a general-purpose computer programming language originally designed in 1966 for the healthcare industry. Its differentiating feature is its "built-in" database, enabling high-level access to disk storage using simple symbolic program variables and subscripted arrays; similar to the variables used by most languages to access main memory. [Read more...](https://en.wikipedia.org/wiki/MUMPS)
The implementations currently available are:
- [Intersystems (Caché)](http://www.intersystems.com/)
- [FIS (GT.M)](http://www.fisglobal.com/products-technologyplatforms-gtm)
- [MUMPS Database and Language by Ray Newman](http://sourceforge.net/projects/mumps/)
- [Open Mumps](http://www.cs.uni.edu/~okane/)
2019-09-26 13:04:37 -04:00
The examples in this tutorial are run with GT.M.
2019-09-23 11:33:02 -04:00
## Prerequisites
2019-09-26 13:04:37 -04:00
- [GT.M Administration and Operations Guide](http://mumps.cz/gtm/books/ao/UNIX_manual/ao_UNIX_screen.pdf)
- [The GT.M Programmer's Guide](http://www.mumps.cz/gtm/books/pg/UNIX_manual/webhelp/content/preface.html)
2019-09-26 13:04:37 -04:00
- [GT.M Message and Recovery Procedures Manual](http://www.mupip.pl/books/mr/manual/titlepage.html)
2019-09-25 10:26:47 -04:00
- [MUMPS Technology Portal](http://mumps.cz/)
2019-09-26 10:04:21 -04:00
### Additional Documentation
- [Sourceforge](http://mumps.sourceforge.net/)
2019-09-25 10:26:47 -04:00
### GPL Mumps
2019-09-26 13:04:37 -04:00
- [The Mumps Programming Language](https://www.cs.uni.edu/~okane/)
- [Mumps Language Users' Guide](https://www.cs.uni.edu/~okane/source/MUMPS-MDH/ReadMe.pdf)
- [Mumps Language Quick Introduction & Tutorial](https://www.cs.uni.edu/~okane/source/MUMPS-MDH/MumpsTutorial.pdf)
2019-09-25 10:26:47 -04:00
2019-09-26 13:04:37 -04:00
---
2019-09-25 10:26:47 -04:00
2019-09-26 13:04:37 -04:00
## Quick Setup
2019-09-25 10:26:47 -04:00
To install GT.M on Debian based OS:
apt-get install fis-gtm
Set up the environment variables:
source /usr/lib/x86_64-linux-gnu/fis-gtm/V6.3-003A_x86_64/gtmprofile
2019-09-25 10:26:47 -04:00
Open the GT.M prompt:
gtm
GTM>write "Hello world"
Hello world
GTM>halt
To uninstall GT.M:
apt-get purge fis-gtm
---
2019-09-25 12:51:51 -04:00
## Run the Examples
Copy the example of your choice into `$gtmdir/$gtmver/r`:
2019-09-25 12:51:51 -04:00
2019-09-29 04:54:43 -04:00
cp -r <your-folder>/mumps-examples/06-databases/basic-sql-blog/* $gtmdir/$gtmver/r
Or alternatively create a symbolic link:
2019-09-29 04:54:43 -04:00
ln -s <your-folder>/mumps-examples/06-databases/basic-sql-blog/* ~/.fis-gtm/V6.3-003A_x86_64/r
2019-09-28 13:18:27 -04:00
Then run the example:
mumps -run ^Main
2019-09-25 12:51:51 -04:00
---
2019-09-23 11:33:02 -04:00
## 1. The Very Basics
2019-09-25 13:14:12 -04:00
### [`HelloWorld.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/HelloWorld.m)
2019-09-25 10:26:47 -04:00
2019-09-23 11:33:02 -04:00
Hello world
2019-09-25 13:14:12 -04:00
### [`HelloWorldInLoop.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/HelloWorldInLoop.m)
2019-09-25 10:26:47 -04:00
2019-09-23 13:50:48 -04:00
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
2019-09-25 13:14:12 -04:00
### [`HelloWorldInAnotherLoop.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/HelloWorldInAnotherLoop.m)
2019-09-25 10:26:47 -04:00
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
2019-09-25 13:14:12 -04:00
### [`HelloWorldInNestedLoop.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/HelloWorldInNestedLoop.m)
2019-09-25 10:26:47 -04:00
1:1 Hello world
1:2 Hello world
1:3 Hello world
1:4 Hello world
1:5 Hello world
2:1 Hello world
2:2 Hello world
2:3 Hello world
2:4 Hello world
2:5 Hello world
2019-09-25 13:14:12 -04:00
### [`ArithmeticOperations.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/ArithmeticOperations.m)
2019-09-25 10:26:47 -04:00
There were 7 apples, 8 pears and 9 oranges,
a total of 24 fruits in a basket.
Then, something happened:
1 apple, 2 pears and 0 oranges were eaten!
Now there are 21 fruits in the basket,
the average fruit value is 7.
2019-09-24 12:36:34 -04:00
2019-09-25 13:14:12 -04:00
### [`Arrays.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/Arrays.m)
2019-09-25 10:26:47 -04:00
2019-09-24 12:36:34 -04:00
Approaching the solar system:
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune
Pluto
September 2019:
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
2019-09-26 05:38:49 -04:00
23 24 25 26 27 28 29
30 1 2 3 4 5 6
Genealogical tree:
Harry and Emily had Jack
Associative array:
Have you ever been to London?
### [`ArraysShortened.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/ArraysShortened.m)
2019-09-26 10:04:21 -04:00
> The output obtained is the same as that in [`Arrays.m`](https://github.com/programarivm/mumps-examples/blob/master/01-the-very-basics/Arrays.m)
2019-09-24 15:57:41 -04:00
2019-09-29 04:54:43 -04:00
## 2. Functions
2019-09-24 15:57:41 -04:00
2019-09-29 06:01:06 -04:00
### [`Ascii.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Ascii.m)
The ASCII code of "a" is 97.
### [`Char.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Char.m)
Alphabet:
abcdefghijklmnopqrstuvwxyz
### [`Data.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Data.m)
Genealogical tree:
gtree(1)="Oliver"
gtree(1,1)="James"
gtree(1,1,1)="Harry"
gtree(1,1,1,1,1)="Robert"
gtree(1,1,2)="Emily"
gtree(1,2)="Amelia"
gtree(1,2,1)="Thomas"
gtree(1,2,2)="Jessica"
Data about a few nodes:
$d(gtree("foo")) is 0
$d(gtree(1,1,1,1,1)) is 1
$d(gtree(1,1,1,1)) is 10
$d(gtree(1)) is 11
### [`Extract.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Extract.m)
Original string: Hello world!
Substring: Hello
2019-09-29 04:54:43 -04:00
## 3. Utility Routines
> TODO.
## 4. User Defined Functions
### [`FactorialByReference.m`](https://github.com/programarivm/mumps-examples/blob/master/04-user-defined-functions/FactorialByReference.m)
2019-09-24 15:57:41 -04:00
Enter n: 5
5! = 120
2019-09-29 04:54:43 -04:00
### [`FactorialByValue.m`](https://github.com/programarivm/mumps-examples/blob/master/04-user-defined-functions/FactorialByValue.m)
2019-09-25 14:57:52 -04:00
Enter n: 5
5! = 120
2019-09-29 04:54:43 -04:00
### [`Fibonacci.m`](https://github.com/programarivm/mumps-examples/blob/master/04-user-defined-functions/Fibonacci.m)
2019-09-25 15:55:36 -04:00
Enter n: 9
F(9) = 34
2019-09-26 08:26:32 -04:00
2019-09-29 04:54:43 -04:00
## 5. User Defined Routines
2019-09-26 10:04:21 -04:00
2019-09-29 04:54:43 -04:00
### [`Main.m`](https://github.com/programarivm/mumps-examples/blob/master/05-user-defined-routines/Main.m)
2019-09-26 10:04:21 -04:00
Hello!
Enter n: 9
areaCircle(9) = 254.469
fibonacci(9) = 34
factorialByVal(9) = 362880
factorialByRef(9) = 362880
2019-09-29 04:54:43 -04:00
> For further details also visit [MyMathRoutines.m](https://github.com/programarivm/mumps-examples/blob/master/05-user-defined-routines/MyMathRoutines.m)
2019-09-26 10:04:21 -04:00
2019-09-29 04:54:43 -04:00
## 6. Databases
2019-09-26 08:26:32 -04:00
2019-09-29 04:54:43 -04:00
### [`basic-sql-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/Main.m)
2019-09-29 06:25:27 -04:00
User created:
^users(1)="alice~password~alice-jones@no-reply.com~Alice Jones"
2019-09-29 06:25:27 -04:00
User created:
^users(2)="bob~password~bob-smith@no-reply.com~Bob Smith"
2019-09-29 06:25:27 -04:00
User fetched (1):
data("email")="alice-jones@no-reply.com"
data("fullname")="Alice Jones"
data("password")="password"
data("username")="alice"
2019-09-29 06:25:27 -04:00
User updated (1):
^users(1)="amelia~password~amelia-roberts@no-reply.com~Amelia Roberts"
2019-09-29 06:25:27 -04:00
User fetched (1):
data("email")="amelia-roberts@no-reply.com"
data("fullname")="Amelia Roberts"
data("password")="password"
data("username")="amelia"
2019-09-29 06:25:27 -04:00
User deleted (2)
User fetched (2):
data("email")=""
data("fullname")=""
data("password")=""
data("username")=""
Database successfully dropped!
2019-09-27 06:30:58 -04:00
For further details also visit:
2019-09-29 04:54:43 -04:00
- [`Database.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/routines/Database.m)
- [`User.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/routines/User.m)
2019-09-29 04:54:43 -04:00
### [`basic-sql-blog/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/Main.m)
2019-09-27 06:21:17 -04:00
2019-09-29 06:25:27 -04:00
Users:
^users(1)="alice~password~alice-jones@no-reply.com~Alice Jones"
^users(2)="bob~password~bob-smith@no-reply.com~Bob Smith"
Categories:
^categories(1)="foo~Foo"
^categories(2)="bar~Bar"
^categories(3)="foobar~Foobar"
Posts:
^posts(1,1,1)="lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
^posts(2,1,1)="donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu."
^posts(3,3,2)="curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi."
^posts(4,3,2)="donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante."
Comments:
^comments(1,1)="This is awesome! Thank you."
^comments(2,2)="Thank you so much for sharing this."
2019-09-28 18:35:31 -04:00
Category fetched (3):
2019-09-29 06:25:27 -04:00
data("description")="Foobar"
data("slug")="foobar"
2019-09-28 18:25:47 -04:00
2019-09-28 18:35:31 -04:00
Post fetched (1):
2019-09-29 06:25:27 -04:00
data("description")="Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
data("slug")="lorem-ipsum"
data("title")="Lorem ipsum"
2019-09-27 13:48:25 -04:00
2019-09-28 18:36:55 -04:00
Posts fetched by category (3):
2019-09-29 06:25:27 -04:00
data(3,3,2)="curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi."
data(4,3,2)="donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante."
2019-09-27 13:48:25 -04:00
2019-09-28 18:36:55 -04:00
Posts fetched by user (1):
2019-09-29 06:25:27 -04:00
data(1,1,1)="lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
data(2,1,1)="donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu."
2019-09-27 13:48:25 -04:00
2019-09-28 18:35:31 -04:00
Comment fetched (1):
2019-09-29 06:25:27 -04:00
data("description")="This is awesome! Thank you."
2019-09-27 06:21:17 -04:00
Database successfully dropped!
For further details also visit:
2019-09-29 04:54:43 -04:00
- [`Category.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/routines/Category.m)
- [`Comment.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/routines/Comment.m)
- [`Database.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/routines/Database.m)
- [`Post.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/routines/Post.m)
- [`User.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/routines/User.m)
2019-09-27 06:21:17 -04:00
2019-09-23 11:33:02 -04:00
---
### Contributions
Would you help make this tutorial better? Contributions are welcome.
- Feel free to send a pull request
- Drop an email at info@programarivm.com with the subject "Open MUMPS by Example"
2019-09-29 06:29:50 -04:00
- Say hello on [Twitter](https://twitter.com/programarivm)
2019-09-23 11:33:02 -04:00
Many thanks.