!DupExit statement: Difference between revisions
m (→See also) |
No edit summary |
||
(14 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
The | <!-- FOOTER LEFT "foo" --> | ||
The <var>!DUPEXIT</var> statement conditionally closes the current procedure, and it continues compilation in the procedure (or command level statement) that INCLUDE'd the current procedure. | |||
As such, !DUPEXIT is not a valid statement at command level. It conditionally closes | As such, <var>!DUPEXIT</var> is not a valid statement at command level. It conditionally closes | ||
the current procedure if the explicit or implicit macro variable is defined. If the macro | the current procedure if the explicit or implicit macro variable is defined. If the macro | ||
variable is not defined, the variable is set to defined, and processing continues in the | variable is not defined, the variable is set to defined, and processing continues in the | ||
current procedure. !DUPEXIT really performs the work of two macro statements: | current procedure. <var>!DUPEXIT</var> really performs the work of two macro statements: | ||
<var>!IFNDEF</var> and <var>!DEF</var> | |||
<var>!DUPEXIT</var> can, optionally, be followed by the name of a macro variable. If the macro | |||
!DUPEXIT can, optionally, be followed by the name of a macro variable. If the macro | |||
variable name is not specified, it defaults to the name of the current procedure. In this | variable name is not specified, it defaults to the name of the current procedure. In this | ||
latter case, the length of the procedure name must be less than the setting of the | <b>latter case</b> (i.e., a "naked" <var>!Dupexit</var>), the length of the procedure name must be less than the setting of the | ||
<var>[[LAUDPROC parameter|LAUDPROC]]</VAR> system parameter (unless the parameter is set to 255). | |||
<var>!DUPEXIT</var> can be useful for preventing one-time-only definitions (%variable or | |||
subroutine) from being performed more than once. For example, the <var>!DUPEXIT</var> | |||
statement in the following example prevents subroutine <code>COMMON</code> from being defined | |||
more than once, as long as the subroutine is only defined in procedure <code>COMPLEX</code>: | |||
<p class="code">PROCEDURE COMPLEX | |||
!DUPEXIT | |||
SUBROUTINE COMMON(%INPUT IS FLOAT) | SUBROUTINE COMMON(%INPUT IS FLOAT) | ||
. . . | |||
END SUBROUTINE | END SUBROUTINE | ||
END PROCEDURE </p> | |||
The first time COMPLEX is INCLUDE'd, the !DUPEXIT will not close COMPLEX | The first time <code>COMPLEX</code> is INCLUDE'd, the <code>!DUPEXIT</code> will not close <code>COMPLEX</code> | ||
(because COMPLEX will be undefined), but it will then define COMPLEX. Any | (because <code>COMPLEX</code> will be undefined), but it will then define <code>COMPLEX</code>. Any | ||
subsequent time that COMPLEX is INCLUDE'd, the !DUPEXIT will cause it to be closed | subsequent time that <code>COMPLEX</code> is INCLUDE'd, the <code>!DUPEXIT</code> will cause it to be closed | ||
immediately, because at that point COMPLEX will be defined. | immediately, because at that point <code>COMPLEX</code> will be defined. | ||
If subroutine COMMON might be defined in other procedures, COMPLEX might be | If subroutine <code>COMMON</code> might be defined in other procedures, <code>COMPLEX</code> might be | ||
changed as follows: | changed as follows: | ||
<p class="code">PROCEDURE COMPLEX | |||
!DUPEXIT COMMON | |||
SUBROUTINE COMMON(%INPUT IS FLOAT) | |||
. . . | |||
END SUBROUTINE | |||
END PROCEDURE </p> | |||
This tactic will only work as long as other procedures that define subroutine <code>COMMON</code> | |||
This tactic will only work as long as other procedures that define subroutine COMMON | |||
also: | also: | ||
<ul> | |||
<li>Define it conditionally based on whether <code>COMMON</code> is defined. </li> | |||
<li>Define <code>COMMON</code> if they define the subroutine. </li> | |||
</ul> | |||
This can be done with a <var>!DUPEXIT</var> or with a <var>!IFNDEF</var> and a <var>!DEF</var>. | |||
This can be done with a !DUPEXIT or with a | |||
==See also== | ==See also== | ||
<ul> | <ul> | ||
<li>[[!IFNDEF]] | <li><var>[[SOUL macro facility#!IFNDEF var|!IFNDEF]]</var> </li> | ||
<li>[[!DEF]] | <li><var>[[SOUL macro facility#!DEF var|!DEF]]</var> </li> | ||
</ul> | </ul> | ||
[[Category: | [[Category:SOUL macro facility]] |
Latest revision as of 12:06, 16 July 2019
The !DUPEXIT statement conditionally closes the current procedure, and it continues compilation in the procedure (or command level statement) that INCLUDE'd the current procedure.
As such, !DUPEXIT is not a valid statement at command level. It conditionally closes the current procedure if the explicit or implicit macro variable is defined. If the macro variable is not defined, the variable is set to defined, and processing continues in the current procedure. !DUPEXIT really performs the work of two macro statements: !IFNDEF and !DEF
!DUPEXIT can, optionally, be followed by the name of a macro variable. If the macro variable name is not specified, it defaults to the name of the current procedure. In this latter case (i.e., a "naked" !Dupexit), the length of the procedure name must be less than the setting of the LAUDPROC system parameter (unless the parameter is set to 255).
!DUPEXIT can be useful for preventing one-time-only definitions (%variable or
subroutine) from being performed more than once. For example, the !DUPEXIT
statement in the following example prevents subroutine COMMON
from being defined
more than once, as long as the subroutine is only defined in procedure COMPLEX
:
PROCEDURE COMPLEX !DUPEXIT SUBROUTINE COMMON(%INPUT IS FLOAT) . . . END SUBROUTINE END PROCEDURE
The first time COMPLEX
is INCLUDE'd, the !DUPEXIT
will not close COMPLEX
(because COMPLEX
will be undefined), but it will then define COMPLEX
. Any
subsequent time that COMPLEX
is INCLUDE'd, the !DUPEXIT
will cause it to be closed
immediately, because at that point COMPLEX
will be defined.
If subroutine COMMON
might be defined in other procedures, COMPLEX
might be
changed as follows:
PROCEDURE COMPLEX !DUPEXIT COMMON SUBROUTINE COMMON(%INPUT IS FLOAT) . . . END SUBROUTINE END PROCEDURE
This tactic will only work as long as other procedures that define subroutine COMMON
also:
- Define it conditionally based on whether
COMMON
is defined. - Define
COMMON
if they define the subroutine.
This can be done with a !DUPEXIT or with a !IFNDEF and a !DEF.