[Info-vax] puzzled by DCL symbol substitution
Phillip Helbig---undress to reply
helbig at astro.multiCLOTHESvax.de
Sat Jan 7 07:19:15 EST 2012
After 20 years of VMS, I thought I understand everything, despite a)
unclear examples (e.g. uncleard distinction between to apostrophes
belonging to different symbols and a double apostrophe; the distinction
is not always clear (to the reader, though it is to DCL) in complicated
expressions) and b) some obvious typos in the documentation. In
particular, I'm referring to the three phases of processing, the order
of symbol substitution etc. I'm surprised that the following works:
$ SAVE_VERIFY = 'F$VERIFY(0)'
$ VERIFY_PROCEDURE = "''F$PARSE(F$ENVIRONMENT("PROCEDURE"),,,"NAME")'_VERIFY"
$ VERIFY_PROCEDURE = "''&VERIFY_PROCEDURE'"
$ IF (SAVE_VERIFY .OR. VERIFY_PROCEDURE) THEN SET VERIFY
[code which should be displayed if any verification is set]
$ VERIFY_PROCEDURE = 0*'F$VERIFY(VERIFY_PROCEDURE)' + VERIFY_PROCEDURE
[code which should be displayed if only the special verification is set]
$ EXIT $STATUS + 0*F$VERIFY(SAVE_VERIFY)
The idea is that one has a symbol called <procedure-name>_VERIFY. If it
is defined to 1, TRUE or whatever, then one can use it to turn on verify
within the procedure. If it is 0, FALSE etc then one can turn it off.
Also, if it is UNDEFINED, then it also turns it off. (One can make this
more complicated by having symbols which if defined to 1 or whatever
turn off verification, symbols which affect all procedures,
corresponding logical names which can be translated etc but the
principle is the same.)
The first line is more or less standard: save the current verification
status and turn off verification. The lexical function is expanded so
that this happens before the line is executed; this means that the line
(as well as the three following it) is never displayed, whatever the
value of verify when the procedure starts. (Similarly, in the last line
it is not expanded so that the line is always displayed if verification
was on during procedure and is not displayed otherwise.)
The second line defines a symbol which equates to the name of the
special verify symbol for this procedure.
The third line is magic.
The fourth line turns on verify if it was on before the procedure was
called or if the special verify symbol for this procedure is set.
The fifth line uses the special verify symbol to set the verification
without changing its value, even if it is undefined.
The sixth line restores things to what they were when the procedure
started.
Why does the third line work? The LOGIC is clear: the symbol
VERIFY_PROCEDURE gets expanded to the name of the symbol appropriate for
this procedure, then its value is evaluated. This construction (and
none other of which I am aware) works if the value is 1, 0 (or TRUE,
FALSE etc) or if it is undefined. However, my impression was that a)
apostrophes are evaluated before ampersands and b) ampersands are not
evaluated inside quotes. So why does it work?
Or does the following happen? Here's the line again
$ VERIFY_PROCEDURE = "''&VERIFY_PROCEDURE'"
First, VERIFY_PROCEDURE is set to the string value
"''&VERIFY_PROCEDURE'"; no substitution happens since &VERIFY_PROCEDURE
is not the name of a symbol. Second, the ampersand is evaluated,
resulting in the string "''TEST_VERIFY'" (if the procedure is called
TEST.COM). The following line then becomes
$ IF (SAVE_VERIFY .OR. "''TEST_VERIFY'") THEN SET VERIFY
Then, of course, "''TEST_VERIFY'" is evaluated to its value if it has
one or to an empty string if it is not defined.
Is this really what happens? If it is, and you know that it is, did you
know before reading my guess about what happens?
Does anyone know who invented this?
More information about the Info-vax
mailing list