Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
MUMPS
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Features === ANSI X11.1-1995 gives a complete, formal description of the language; an annotated version of this standard is available online.<ref>{{cite web|url=http://71.174.62.16/Demo/AnnoStd|title=The Annotated M[UMPS] Standards|website=71.174.62.16|access-date=26 February 2018}}</ref> Language features include: ; Data types : There is one universal [[data type]], which is implicitly [[type conversion|coerced]] to string, integer, or floating-point data types as context requires. ; Booleans {{nobold|(called ''truthvalues'' in MUMPS)}}: In IF commands and other syntax that has expressions evaluated as conditions, any string value is evaluated as a numeric value and, if that is a nonzero value, then it is interpreted as True. <code>a<b</code> yields 1 if a is less than b, 0 otherwise. ; Declarations : None. All variables are dynamically created at the first time a value is assigned. ; 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 any {{mono|IF}}, {{mono|ELSE}}, and {{mono|FOR}} command 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 : execution of almost any command can be controlled by following it with a colon and a truthvalue expression. <code>SET:N<10 A="FOO"</code> sets A to "FOO" if N is less than 10; <code>DO:N>100 PRINTERR,</code> 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 one, two, or three characters. ; 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, so the following is perfectly legal MUMPS code: :<syntaxhighlight lang="text"> GREPTHIS() NEW SET,NEW,THEN,IF,KILL,QUIT SET IF="KILL",SET="11",KILL="11",QUIT="RETURN",THEN="KILL" IF IF=THEN DO THEN QUIT:$QUIT QUIT QUIT ; (quit) THEN IF IF,SET&KILL SET SET=SET+KILL QUIT </syntaxhighlight> :MUMPS can be made more obfuscated by using the contracted operator syntax, as shown in this terse example derived from the example above: :<syntaxhighlight lang="text"> GREPTHIS() N S,N,T,I,K,Q S I="K",S="11",K="11",Q="R",T="K" I I=T D T Q:$Q Q Q T I I,S&K S S=S+K Q </syntaxhighlight> ; Arrays : are created dynamically, stored as [[B-tree]]s, are [[sparse matrix|sparse]] (i.e. 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. Built-in functions such as {{mono|$DATA}}, {{mono|$ORDER}}, {{mono|$NEXT}}(deprecated), and {{mono|$QUERY}} functions provide efficient examination and traversal of the fundamental array structure, on disk or in memory. :<syntaxhighlight lang="text"> for i=10000:1:12345 set sqtable(i)=i*i set address("Smith","Daniel")="dpbsmith@world.std.com" </syntaxhighlight> ; Local arrays : variable names not beginning with caret (i.e. "^") are stored in memory by process, are private to the creating process, and expire when the creating process terminates. The available storage depends on implementation. For those implementations using partitions, it is limited to the partition size (a small partition might be 32K). For other implementations, it may be several megabytes. ; Global arrays : <code>^abc, ^def</code>. These are stored on disk, are available to all processes, and are persistent when the creating process terminates. Very large globals (for example, hundreds of gigabytes) 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, <code>@VBL</code> can be used, and effectively substitutes the contents of VBL into another MUMPS statement. <code>SET XYZ="ABC" SET @XYZ=123</code> sets the variable ABC to 123. <code>SET SUBROU="REPORT" DO @SUBROU</code> performs the subroutine named REPORT. This substitution allows for [[lazy evaluation]] and late binding as well as effectively the operational equivalent of "pointers" in other languages. ; Piece function : This breaks variables into segmented pieces guided by a user specified separator string (sometimes called a "delimiter"). Those who know [[awk]] will find this familiar. <code>$PIECE(STRINGVAR,"^",3)</code> means the "third caret-separated piece of {{mono|STRINGVAR}}." The piece function can also appear as an assignment (SET command) target. :<code>$PIECE("world.std.com",".",2)</code> yields {{samp|std}}. :After :<syntaxhighlight lang="text"> SET X="dpbsmith@world.std.com" </syntaxhighlight> :<code>SET $P(X,"@",1)="office"</code> causes X to become "office@world.std.com" (note that {{mono|$P}} is equivalent to {{mono|$PIECE}} and could be written as such). ; Order function : This function treats its input as a structure, and finds the next index that exists which has the same structure except for the last subscript. It returns the sorted value that is ordered after the one given as input. (This treats the array reference as a content-addressable data rather than an address of a value.) :<syntaxhighlight lang="text"> Set stuff(6)="xyz",stuff(10)=26,stuff(15)="" </syntaxhighlight> :<code>$Order(stuff(""))</code> yields {{samp|6}}, <code>$Order(stuff(6))</code> yields {{samp|10}}, <code>$Order(stuff(8))</code> yields {{samp|10}}, <code>$Order(stuff(10))</code> yields {{samp|15}}, <code>$Order(stuff(15))</code> yields {{samp|""}}. :<syntaxhighlight lang="text"> Set i="" For Set i=$O(stuff(i)) Quit:i="" Write !,i,10,stuff(i) </syntaxhighlight> :Here, the argument-less {{mono|For}} repeats until stopped by a terminating {{mono|Quit}}. This line prints a table of {{mono|i}} and {{code|stuff(i)}} where {{mono|i}} is successively 6, 10, and 15. :For iterating the database, the Order function returns the next key to use. :<syntaxhighlight lang="text"> GTM>S n="" GTM>S n=$order(^nodex(n)) GTM>zwr n n=" building" GTM>S n=$order(^nodex(n)) GTM>zwr n n=" name:gd" GTM>S n=$order(^nodex(n)) GTM>zwr n n="%kml:guid" </syntaxhighlight> MUMPS supports multiple simultaneous users and processes even when the underlying operating system does not (e.g., [[MS-DOS]]). Additionally, there is the ability to specify an environment for a variable, such as by specifying a machine name in a variable (as in <code>SET ^|"DENVER"|A(1000)="Foo"</code>), which can allow you to access data on remote machines.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
MUMPS
(section)
Add topic