From: fairfield@slacvx.slac.stanford.edu
Newsgroups: comp.os.vms,vmsnet.misc
Subject: SUMMARY: Delayed lexical evaluation in a DCL symbol?
Summary: Use a one-line command file instead.
Date: 4 Oct 92 03:55:39 GMT
Organization: Stanford Linear Accelerator Center

Last week, I asked the following:

In article <1992Oct1.121433.1@slacvx.slac.stanford.edu>,
                        fairfield@slacvx.slac.stanford.edu writes:
>     DCL question: how can you get delayed evaluation of a lexical function
>     ------------  in a symbol?
>
>         Why?  I'd like to define a symbol, like "PARENT", that does an
>     ATTACH to the parent (OWNER) process if I'm in a subprocess.  For
>     example, I SPAWN out of ANU-News, do some stuff, then I'd like to
>     ATTACH back to the parent process running News rather than log out
>     of the subprocess.

    The answer is, of course, you CAN'T.  (Geez, I _knew_ that.  I just
hoped some DCL guru had a trick way around it...)  OTOH, there's no need for
tricks!
^^^^^^
    The solution is simple: put the single line for which you wanted delayed
evaluation of the lexical in a command file, and define a symbol to execute
the command file!  I believe this will work for 90% of the cases for which
one _thinks_ one wants delayed lexical evaluation.  The example I used was:

>       $ PARENT == "ATTACH/ID='F$GETJPI("""",""OWNER"")"

The "correct" solution is just:

        $ PARENT == "@SYS$LOGIN:ATTACH_OWNER.COM"

with the contents of ATTACH_OWNER.COM being the single line:

        $ ATTACH/ID='F$GETJPI("","OWNER")

I actually embellished the command file a bit to avoid DCL giving an error
if you were to issue the command from the master process, for which
F$GETJPI("","OWNER") returns a null string.  Here is ATTACH_OWNER.COM:

-----------------------------------------------------------------------------
$ ownpid = F$GETJPI("","OWNER")
$ IF ownpid.EQS.""
$ THEN
$   WRITE SYS$OUTPUT "%ATTACH-E-ORPHAN, you have no parents.  I'm so sorry."
$   EXIT
$ ENDIF
$ ATTACH /ID='ownpid
------------------------------------------------------------------------------

    In LOGIN.COM, I have two symbols defined, one to attach to the parent
process, the other to attach to the _master_ process:

        $ OWN*ER == "@SYS$LOGIN:ATTACH_OWNER"
        $ MASTER == "ATTACH/ID=" + F$GETJPI("","PID")


    Thanks to the following three gentlemen for their answers and 
suggestions:
                Dick Munroe    <munroe@dmc.com>
                John Simutis   <simutis@ingres.com>
                Joe Lawrence   <jfl@hobbes.cca.cr.rockwell.com>
                Roland Roberts <rbr4@uhura.cc.rochester.edu>

However, none were able to provide a method that would _always_ get me back
to the parent process (not just the MASTER_PROCESS) even when I didn't spawn
into that process through a command file.  (The latter method, BTW, can be
useful for generating subprocesses with regular and known process names,
e.g. KHF_1, KHF_2... instead of FAIRFIELD_1, FAIRFIELD_2..., etc.) Thanks to
Roland for jogging me out of my stupor w.r.t. LOCAL symbols: the last
paragraph of my post said I couldn't find a way to reliably use the LOCAL
symbols defined within a command file which spawns the subprocess. That's
wrong.  It does work.  I proved it to myself afterwards.

                Cheers, Ken
--
 Dr. Kenneth H. Fairfield    |  Internet: Fairfield@Slacvx.Slac.Stanford.Edu
 SLAC, P.O.Box 4349, MS 98   |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309        |  BITNET    Fairfield@Slacvx
 ----------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...