Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

$SELECT

M[UMPS] by Example

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.

Set Y=$Select(X=7:"HI",1:"BYE")
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:

$Select(COND:VALUE,1:VALUE)
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.

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-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

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 15-Nov-2023, 13:13:02.

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