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

NEW

M[UMPS] by Example

Right Hand Pointer

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

New A,B,C
New
New (A,B,C)

Note that New A(1) or  New (A(1),B) is not allowed.

 Kill X
 Do SUB
 Write $Data(X)
 Quit
 ;
SUB New X
 Set X=1
 Quit

Within the subroutine, a new instantiation of local variable X is created; at the Quit command that terminates the subroutine, that instantiation is deleted. So, after execution of the subroutine, local variable X is undefined again, and the value 0 will be written.

 Set A="President" Do SUB
 Write A
 Quit
 ;
SUB New A
 Set A="Prime minister"
 Quit

Within the subroutine, a new instantiation of local variable A is created; at the Quit command that terminates the subroutine, that instantiation is deleted. So, after execution of the subroutine, local variable A is once again equal to "President", and that value will be written.

 Set A="President"
 Do SUB1(.A)
 Write !,A
 Quit
 ;
SUB1(B) Do SUB2 Write !,B
 Quit
 ;
SUB2 New B
 Set B="Prime minister"
 Quit

Within the subroutine SUB2, a new instantiation of local variable B is created; at the Quit command that terminates this subroutine, that instantiation is deleted. So, after execution of the subroutine SUB2, local variable B is once again equal to "President", and that value will be written.

After this, control is returned to the main routine. Since the value of parameter variable B didn't change within the subroutine SUB1, the value of local variable A is not affected, and the value "President" will be written once again.

Names that appear in a "formal parameter list" are NEWed implicitly. The example below illustrates this feature. Assume that the following routine is executed:

DEMONEW ; Show Implicit NEW
 New t1,t2
 Set top=1 Do Show("At top")
 Set t1="One",t2="Two" Do Second(.t1,t2)
 Do Show("Back at top")
 Quit
 ;
Second(p1,p2) ;
 Do Show("At start of Second")
 Kill top
 Set top="top" Do Third
 Do Show("At end of Second")
 Quit
 ;
THIRD ;
 Do Show("In Third")
 New p1,p2,top Do Show("In Third after New")
 Kill
 Do Show("In Third after Kill")
 Quit
 ;
Show(Text) ;
 Write !!,Text
 Write !,"p1:",$Get(p1,"<undefined>")
 Write ", p2:",$Get(p2,"<undefined>")
 Write ", t1:",$Get(t1,"<undefined>")
 Write ", t2:",$Get(t2,"<undefined>")
 Write ", top:",$Get(top,"<undefined>")
 Quit
 ;

The result of running this program would be:

>Do ^DEMONEW

At top
p1:<undefined>, p2:<undefined>, t1:<undefined>, t2:<undefined>, top:1

At start of Second
p1:One, p2:Two, t1:One, t2:Two, top:1

In Third
p1:One, p2:Two, t1:One, t2:Two, top:top

In Third after New
p1:<undefined>, p2:<undefined>, t1:One, t2:Two, top:<undefined>

In Third after Kill
p1:<undefined>, p2:<undefined>, t1:<undefined>, t2:<undefined>, top:<undefined>

At end of Second
p1:<undefined>, p2:Two, t1:<undefined>, t2:<undefined>, top:top

Back at top
p1:<undefined>, p2:<undefined>, t1:<undefined>, t2:<undefined>, top:top
>

Since the New command operates only on local variables, there are no examples with naked references.

Approved addition for a future M[UMPS] Language Standard.

The special variable $Test may occur as an argument of the New command.

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 29-Nov-2011, 22:27:16 .

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