Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples
Left Hand Pointer

routine

M[UMPS] by Example

Right Hand Pointer

This little gem comes to us through Paul Kadow and John Mitchell (original author unknown). It was created when they worked at Digital Equipment Corporation.

  ; The ultimate M[UMPS] program  --  self documenting
  ;
P R I N T S (A,L)=1,(S,T)=I N G
  G I V E N A      
O F A=L:L:S Q:U=A  R E S B=E L O W (A*A),!
I S (U,R,E)=T H 1 N K I T=S G O O D
  ;

Looking quickly at the letters in the code one might see a suggestion that there is something with "prints a listing, given A, of all squares below".
The A*A seems to confirm that.

Now let's have a real look:

The program starts out by reading a number into a local variable (I) and copying that value into a couple of other local variables (S and T).
In passing, two local variables are Newed (T and G)

The next line shows us one of the interesting ways of adding comments to a M[UMPS] program without having to resort to inserting a semi-colon: after a Goto command, the rest of the line is not executed, so the program GOes to label I and the language processor ignores the text V E N A.

At that line, three more variables receive the value that is in local variable T (U, R and E), which was the same as local variable I.

After all this hard labor, the language processor takes a well-deserved rest (Hang 1).

Local variable K is Newed, and if the values of local variables T and S are equal (they were set to the same value in the first line, so that is still the case), we Goto label O (and the language processor ignores the "comment" O D, after all: OD-ing is not considered desirable anyway).

At this line (O), there is a loop: local variable A loops from the value 1 with steps of 1 until the value of S (which is equal to the value of I, being the value entered by the end-user in the very first line).
The loop has an alternate end: when the value of local variable U is equal to local variable A (the loop-counter), the loop ends.
This means that the final value that would result from A=L:L:S (A=1:1:I) will signal the end of the loop, and the square of I will never be printed (but now I'm getting ahead of myself).

Next, the program reads another value into local variable E, and copies that value into local variable B.
Then, a Lock command is issued: the name O is added to the LOCK-table (or the program will wait until that is possible).

Now we finally get to the purpose of the program: it writes the value of A*A (the square of the loop-counter), and a new-line code-sequence.

So, while the loop is active, the list of squares for the numbers 1 through (I-1) will be displayed, waiting for user-input before each number is printed.
When the loop is complete, the line with label I will be executed again. Since none of the variables I, T or S have received any new values, the loop at line O will be repeated, and again, and again, and again...

While this program is cute and fun, it also illustrates a number of errors that are quite common in software (be it written in M[UMPS] or any other programming language):

Keeping those issues in mind, one might rewrite this code as:

 New i,max
 Write !,"Highest number: " Read max
 Write !!,"Number     Square"
 Write !,"======     ======"
 For i=1:1:max Write !,$Justify(i,5),$Justify(i*i,11)
 Write !!
 Quit

which is a whole lot less fun, but probably also a lot more effective.

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2017 MUMPS Development Committee;
Copyright © Examples: 1995-2017 Ed de Moel;
Copyright © Annotations: 2003-2017 Jacquard Systems Research.

The information in this page is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 13-Sep-2014, 11:37:42 .

For comments, contact Ed de Moel (demoel@jacquardsystems.com)