New

NEWコマンドは、ローカル変数のコピーを "スタック" し、そして、それら変数を再初期化します。DO、XECUTE、外部関数からの明示的または暗黙的なQUITは、NEWされた変数を "アンスタック:unstacks" します、すなわち、スタックされた値に変数を復元します。現在の実行スコープがアクティブな時だけ、NEWが持続します。

NEWコマンドのフォーマットは:

N[EW][:tvexpr] [[(]lvn[,...][)][,...]]

NEWコマンドは、ローカル変数のスコープを限定するための手段を提供します。 NEWは、添字なしのローカル名だけで操作し、名付けられた配列全体上で動作します。

NEWの例

例:

NEW1;
  Set A(1)=1,B=4,C=5
  Write !,"VARIABLES BEFORE NEW:",!
  ZWRite
  Do LABEL
  Write !,"VARIABLES AFTER RETURN:",!
  ZWRite
  Quit
LABEL
  New A Set C=7
  Write !,"VARIABLES AFTER NEW:",!
  ZWRite
  Quit

実行結果:

VARIABLES BEFORE NEW:
A(1)=1
B=4
C=5
VARIABLES AFTER NEW:
B=4
C=7
VARIABLES AFTER RETURN:
A(1)=1
B=4
C=7

例:

NEW2;
  Set (A,B,C,D)="TEST"
  Do LABEL
  Write !,"VARIABLES AFTER RETURN:",!
  ZWRite
  Quit
LABEL
  New (B,C) SET (A,B,Z)="NEW"
  Write !,"VARIABLES AFTER EXCLUSIVE NEW:",!
  ZWRite
  Quit

実行結果:

VARIABLES AFTER EXCLUSIVE NEW:
A="NEW"
B="NEW"
C="TEST"
Z="NEW"
VARIABLES AFTER RETURN:
A="TEST"
B="NEW"
C="TEST"
D="TEST"

例:

/usr/lib/fis-gtm/V5.4-002B_x86/gtm -run ^stackalias   
stackalias ; Demonstrate New with alias
  ZPrint ; Print this program
  Set A=1,*B=A,*C(2)=A ; Create some aliases
  Write "------------",!
  Write "ZWRite in the caller before subprogram",!
  ZWRite
  Do S1 ; Call a subprogram
  Write "------------",!
  Write "ZWRite in the caller after subprogram - A association is restored",!
  ZWRite
  Quit
 ;
S1  ; Subprogram
  New A
  Set A="I am not an alias",B="I am an alias"
  Write "------------",!
  Write "ZWRite in the subprogram with new A and modified B",!
  ZWRite
  Quit
------------
ZWRite in the caller before subprogram
A=1 ;*
*B=A
C=3
*C(2)=A
D=4
------------
ZWRite in the subprogram with new A and modified B
A="I am not an alias"
B="I am an alias" ;*
C=3
*C(2)=B
D=4
------------
ZWRite in the caller after subprogram - A association is restored
A="I am an alias" ;*
*B=A
C=3
*C(2)=A
D=4

以下は基本的に前の例と同じですが、排他的NEWを使用しています。

$ /usr/lib/fis-gtm/V5.4-002B_x86/gtm -run ^stackalias1
stackalias1 ; Demonstrate New with alias
  ZPrint ; Print this program
  Set A=1,*B=A,*C(2)=A ; Create some aliases
  Write "------------",!
  Write "ZWRite in the caller before subprogram",!
  ZWRite
  Do S1 ; Call a subprogram
  Write "------------",!
  Write "ZWRite in the caller after subprogram - A association is restored",!
  ZWRite
  Quit
 ;
S1  ; Subprogram
  New (B)
  Set A="I am not an alias",B="I am an alias"
  Write "------------",!
  Write "ZWRite in the subprogram - Notice B is flagged as an alias",!
  ZWRite
  [参考] Quit
------------
ZWRite in the caller before subprogram
A=1 ;*
*B=A
C=3
*C(2)=A
D=4
------------
ZWRite in the subprogram with new A and modified B
A="I am not an alias"
B="I am an alias" ;*
C=3
*C(2)=B
D=4
------------
ZWRite in the caller after subprogram - A association is restored
A="I am an alias" ;*
*B=A
C=3
*C(2)=A
D=4

排他的なNEWは、名前または lvn と配列の両方の間の1つだけ関連が見ることができる中で、スコープを作成することができます。このケースでは、ZWRITEは、それにもかかわらず、その配列が1つだけの名前またはlvn からアクセス可能な場合であっても、エイリアスの存在を示しています。

inserted by FC2 system