M[UMPS] Functions - $S[ELECT]

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

This function returns a value that is one of a number of specified choices.

SET Y=$SELECT(A=3:5,1:0)
If A=3 then the function-value will be 5. Under all other circumstances the function-value will be 0.

Y will receive the value "HI" when X=7. Under all other circumstances Y will receive the value "BYE".

Assume that X=1:

Reference   Value
$SELECT(X=1:8,2=3:8)   8
$SELECT(X=1:8,2=2:0)   8
$SELECT(X=2:8,2=2:0)   0
$SELECT(X=2:8,2=3:0)   Error (M4)

Assume that Y="B" and X=1:
$SELECT(X=3:8,Y="B":"Hello",X=1:13) yields "Hello".
$SELECT(X=Y:B(1),Y="A":P(2,3),1:3) yields 3.

Assume that ^A(1)="One" and Y="Two":
$SELECT(X=1:^A(1),Y:S) yields "One".
The naked indicator becomes "^A(".

Assume that X=5.
$SELECT(X<5:"Small",X>5:"Large") is erroneous
$SELECT(X<5:"Small",X>5:"Large",X=5:"Equal") returns "Equal"
$SELECT(X'>5:"Small",X'<5:"Large",X=5:"Equal") returns "Small"

Examples with naked references:

SET ^ABC(1,2)="reset naked indicator"
; Naked indicator is now ^ABC(1,
SET ^(3,4)=$SELECT(^(5,6):^(7,8),1:^(9,10))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; if ^ABC(1,5,6) is true:
; 3. store ^(3,4) = ^ABC(1,5,7,3,4)
; quit with naked indicator equal to ^ABC(1,5,7,3,
; else
; 3. fetch ^(9,10) = ^ABC(1,5,7,9,10)
' 4. store ^(3,4) = ^ABC(1,5,7,9,3,4)
; Naked indicator is now: ^ABC(1,5,7,9,3,
Note that the eventual value of the naked indicator depends on the number of expressions that need to be evaluated.

This document is © Ed de Moel, 1995-2005.
It is part of a book by Ed de Moel that is published under the title "M[UMPS] by Example" (ISBN 0-918118-42-5).
Printed copies of the book are no longer available.