## SET

### M[UMPS] by Example

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

Usual Set commands:

Set X=1

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:

• Set One=value
Set Two=value
Set Three=value
et cetera
• Set (One,Two,Three,et cetera)=value
• Set Var1=value,Var2=value,Var3=value,et cetera
• Set Var(1)=value,Var(2)=value,Var(3)=value,et cetera
• For i=1:1:n Set Var(i)=value
• For i=1:1:n Set Key("Button"_i)=value
• Set list="One Two Three et cetera"
For i=1:1:n Set @\$Piece(list," ",i)=value
• For i=1:1:n Set name="Var"_i,@name=value
• For i=1:1:n Set @("Var"_i)=value
• For i=1:1:n Set command="Set Var"_i_"=value" Xecute command
• For i=1:1:n Xecute "Set Var"_i_"=value"

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"

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,