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.
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.
This document describes the various commands that are defined in the M[UMPS] language standard (ANSI X11.1, ISO 11756).
The information in this document is NOT authoritative
and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an
authoritative definition.
In this document, information is included that will
appear in
future standards.
The MDC cannot guarantee that these 'next'
standards will indeed appear.