
|
Page: Summary of Key Language Features
Main article
| Home > Child Health > Summary of Key Language Features |
The following incomplete and informal sketch seeks to give programmers familiar with other languages a feeling for what MUMPS is like. Neither the language description, nor the descriptions of each feature, are complete and many significant features have been omitted for brevity. These notes reflect the language circa 1994. ANSI X11.1-1995 gives a complete, formal description of the language; an annotated version of this standard is available online.
Data types: There is one universal datatype, automatically interpreted/converted to string, integer, or floating-point number as context requires. It is somewhat like the "variant" type found in Visual BASIC 6.0 and earlier.
Booleans: In IF statements, and other conditional statements, any nonzero value is treated as True. a
Declarations: None. All variables are dynamically created on first reference.
Lines: are important syntactic entities, unlike their status in languages patterned on C or Pascal. Multiple statements per line are allowed and are common. The scope of IF and FOR is "the remainder of current line."
Case sensitivity: Commands and intrinsic functions are case-insensitive. In contrast, variable names and labels are case-sensitive. There is no special meaning for upper vs. lower-case and few widely followed conventions. The percent sign (%) is legal as first character of variables and labels.
Postconditionals: SET:N<10 A="FOO" sets A to "FOO" if N is less than 10; DO:N>100 PRINTERR, performs PRINTERR if N is greater than 100. This construct provides a conditional whose scope is less than a full line.
Abbreviation: You can abbreviate nearly all commands and native functions to a single character.
Reserved words: None. Since MUMPS interprets source code by context, there is no need for reserved words. You may use the names of language commands as variables. There has been no obfuscated MUMPS contest as in C, despite the potential of examples such as the following, perfectly legal, MUMPS code:
GREPTHIS()
NEW SET,NEW,THEN,IF,KILL,QUIT SET IF="KILL",SET="11",KILL="l1",QUIT="RETURN",THEN="KILL"
IF IF=THEN DO THEN
QUIT:$QUIT QUIT QUIT ; (quit)
THEN IF IF,SET&KILL SET SET=SET+KILL QUIT
Arrays: are created dynamically, stored as B-trees, use almost no space for missing nodes, can use any number of subscripts, and subscripts can be strings or numeric (including floating point). Arrays are always automatically stored in sorted order, so there is never any occasion to sort, pack, reorder, or otherwise reorganize the database. $ORDER, $ZPREVIOUS, and $QUERY functions provide efficient traversal of the fundamental array structure, on disk or in memory.
for i=10000:1:12345 set sqtable(i)=i*i
set address("Smith","Daniel")="dpbsmith@world.std.com"
Local arrays: variable names not beginning with caret are stored in memory by process, are private to the creating process, expire when the creating process terminates. The available storage depends on partition size, but is typically small (32K). Efficient memory allocation means that this was little practical impediment in former, memory starved, times and is still less an issue today. MUMPS' development history has led to considerable memory efficiency in nearly all implementations, MUMPS has had less code bloat than nearly all otherwise similar systems.
Global arrays: ^abc, ^def. These are stored on disk, are available to all processes, and are persistent when the creating process terminates. Very large globals (eg, hundreds of megabytes) are practical and efficient in most implementations. This is MUMPS' main "database" mechanism. It is used instead of calling on the operating system to create, write, and read files.
Indirection: in many contexts, @VBL can be used, and effectively substitutes the contents of VBL into another MUMPS statement. SET XYZ="ABC" SET @XYZ=123 sets the variable ABC to 123. SET SUBROU="REPORT" DO @SUBROU performs the subroutine named REPORT. This is effectively the operational equivalent of "pointers" in other languages.
Piece function: This breaks variables into pieces guided by a user specified separator character. Those who know awk will find this familiar. $PIECE(STRINGVAR,"^",3) means the "third caret-separated piece of STRINGVAR." It can appear as an assignment target. After
SET X="dpbsmith@world.std.com"
$PIECE("world.std.com",".",2) yields "std" SET $P(X,"@",1)="office" causes X to become "office@world.std.com" (note that $P is equivalent to $PIECE and could be written as such).
Order function
Set stuff(6)="xyz",stuff(10)=26,stuff(15)=""
$Order(stuff("")) yields 6, $Order(stuff(6)) yields 10, $Order(stuff(8)) yields 10, $Order(stuff(10)) yields 15, $Order(stuff(15)) yields "".
Set i="" For Set i=$O(stuff(i)) Quit:i="" Write !,i,?10,stuff(i)
Here, the argument-less For repeats until stopped by a terminating Quit. This line prints a table of i and stuff(i) where i is successively 6, 10, and 15.
For a thorough listing of the rest of the MUMPS commands, operators, functions and special variables, see the online resource
* MUMPS by Example, or the (out of print) book of the same name by Ed de Moel. Much of the language syntax is detailed there, with examples of usage. There is also an annotated language standard, showing the evolution of the language and differences between versions of the ANSI standard. It is available at
* Annotated MUMPS Language Standard
|
Important notice:
The content is not intended to be a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other
qualified health provider with any questions you may have regarding a medical condition.
|