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

SET

M[UMPS] by Example

Right Hand Pointer

Introduced in the 1977 ANSI M[UMPS] language standard.

Usual Set commands:

Set X=1
Set ANSWER="Yes"

There seems to be a lasting confusion about the use of indirection with the Set command: in an expression like Set abc=@def, the value of def must be the name of a variable (be it a local, global, or "special" one).
This type of indirection is called "name indirection".

A different form of indirection is "argument indirection". While "argument indirection" can be used with any command, it may be confusing that
   Set A="B",B="$$NOW^XLFDT" Write !,A,!,@A,!,@@A
is valid, it would return values like:
   B
   $$NOW^XLFDT
   3170531.153451

But Set X=@A Write !,X Set X=@@A Write !,X
would return a syntax error for the X=@@A part.

The reason for this error is that the part on the right-hand side of the "=" sign is evaluated as a "name indirection". To use indirection in this context, "argument indirection" should be used:
   Set X=@A Write !,X Set @("X="_@A) Write !,X
would return the desired result:
   $$NOW^XLFDT
   3170531.2002

Suppose that there is a need to set a group of variables all to the same value. There are many ways to achieve a goal like this. Note that it depends on the nature of the application whether it is more efficient to use an array, or to use individual variables:

Examples with naked references:

Set ^A(8)=8
Set ^(9)=9
Set ^(10,11)=1011
Set ^(^(2,3),^(4,5))=^(6.7)

In these Set commands, the naked indicator changes in the order described below:

Expression naked indicator Resulting reference
Set ^A(8)=8 ^A( ^A(8)
Set ^(9)=9 ^A( ^A(9)
Set ^(10,11)=14 ^A(10, ^A(10,11)

Set ^(^(2,3),^(4,5))=^(6.7)

Expression naked indicator Resulting reference
^(2,3) ^A(10,2, ^A(10,2,3)
^(4,5) ^A(10,2,4, ^A(10,2,4,5)
^(6,7) ^A(10,2,4,6, ^A(10,2,4,6,7)
^("x","y") ^A(10,2,4,6,"x", ^A(10,2,4,6,"x","y")

(Assuming that ^A(10,2,3)="x" and ^A(10,2,4,5)="y".)

Addition in the 1984 ANSI M[UMPS] Language Standard:

It is allowed to specify a reference to $Piece on the left hand side of the equal sign in a Set command.

Set X="This is an test"

Reference   Value
Set $Piece(x," ",3)="a"   X="This is a test"
Set $Piece(x," ",2)="was no"   X="This was no test"
Set $Piece(x," ",3)="a"   X="This  test"

Addition in the 1995 ANSI M[UMPS] Language Standard:

It is allowed to specify a reference to $Extract on the left hand side of the equal sign in a Set command.

Set X="ABCDEFG"

Reference   Value
Set $Extract(X,3)="a"   X="ABaDEFG"
Set $Extract(X,2)="xxx"   X="AxxxaDEFG"
Set $Extract(X,2,6)=""   X="AEFG"

Approved for addition in a future M[UMPS] Language Standard:

It is allowed to specify a reference to $QSubscript on the left hand side of the equal sign in a Set command.

Set N="^|""where""|ABC(11,22,33)"

Reference   Value
Set $QSubscript(N,–1)="A"   N="^|""A""|ABC(11,22,33)"
Set $QSubscript(N,0)="xxx"   N="^|""A""|xxx(11,22,33)"
Set $QSubscript(N,2)=9   N="^|""A""|xxx(11,9,33)"
Set $QSubscript(N,10)=123   N="^|""A""|xxx(11,9,33,"","","","","","",123)"

More examples with naked indicators:

Set TO=FROM
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=^(5,6)

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. store ^(3,4) = ^ABC(1,5,3,4)
; naked indicator is now: ^ABC(1,5,3,

Set (TO,LIST)=FROM
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set (^(3,4),^(5,6))=^(7,8)

; 1. fetch ^(7,8) = ^ABC(1,7,8)
; 2. store ^(3,4) = ^ABC(1,7,3,4)
; 3. store ^(5,6) = ^ABC(1,7,3,5,6)
; naked indicator is now: ^ABC(1,5,3,

Set $Extract(VALUE,FROM,TO)=VALUE
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set $Extract(^(3,4),^(5,6),^(7,8))=^(9,10)

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3: if ^ABC(1,5,6,7) < ^ABC(1,5,6) or if ^ABC(1,5,6,7) < 1
; don't store, naked indicator is ^ABC(1,5,7,9,
; else continue
; 4. fetch/store ^(3,4) = ^ABC(1,5,7,9,3,4)
; naked indicator is now: ^ABC(1,5,7,9,3,

Set $Piece(VALUE,STRING,FROM,TO)=VALUE
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set $Piece(^(3,4),^(5,6),^(7,8),^(9,10))=^(11,12)

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. fetch ^(9,10) = ^ABC(1,5,7,9,10)
; 4. if ^ABC(1,5,7,9,10) < ^ABC(1,5,7,8) or
; if ^ABC(1,5,7,9,10) < 1
; don't store, naked indicator is ^ABC(1,5,7,9,11,
; else continue
; 5. fetch/store ^(3,4) = ^ABC(1,5,7,9,11,3,4)
; naked indicator is now: ^ABC(1,5,7,9,11,3,

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 31-May-2017, 20:41:19 .

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