Global Variable Name Environments

M recognizes an optional environment specification in global names. The environment specification designates one of some set of alternative database files.

The syntax for global variable names that include an environment specification is:

          ^|expr|name[(subscript[,...])]
        

In GT.M, the expression identifies the Global Directory for mapping the global variable.

Environment specifications permit easy access to global variables in alternative databases, including other "copies" of active variables in the current database. Environment specifications are sometimes referred to as extended global syntax or extended value syntax.

GT.M also allows:

          ^|expr1,expr2|name[(subscript[,...])]
        

Where the first expression identifies the Global Directory and the second expression is accepted but ignored by GT.M.

To improve compatibility with some other M implementations, GT.M also accepts another non-standard syntax. In this syntax, the leading and trailing up-bar (|) are respectively replaced by a left square-bracket ([) and a right square-bracket (]). This syntax also requires expratoms, rather than expressions. For additional information on expratoms, refer to the "Expressions" section of this chapter.

The formats for this non-standard syntax are:

          ^[expratom1]name[(subscript...)]
        

or

          ^[expratom1,expratom2]name[(subscript...)]
        

Where expratom1 identifies the Global Directory and expratom2 is a dummy variable. Note that the first set of brackets in each format is part of the syntax. The second set of square brackets is part of the meta-language identifying an optional element.

Example:

          
        $ DEFINE GTM$GBLDIR TEST.GLD
        $ MUMPS/DIR
          
          
        GTM>WRITE $ZGBLDIR
        TEST.GLD
        GTM>WRITE ^A
        THIS IS ^A IN DATABASE RED
        GTM>WRITE ^|"M1.GLD"|A
        THIS IS ^A IN DATABASE WHITE
        GTM>WRITE $ZGBLDIR
        TEST.GLD
        GTM>HALT
          
            $ SHOW LOGICAL GTM$GBLDIR
          
          
        TEST.GLD
        

The statement WRITE ^|"M1.GLD"|A writes variable ^A using the Global Directory, M1.GLD, but does not change the current Global Directory.

Example:

        GTM>WRITE $ZGBLDIR
        M1.GLD
        GTM>WRITE ^A
        THIS IS ^A IN DATABASE WHITE
        GTM>WRITE ^|"M1.GLD"|A
        THIS IS ^A IN DATABASE WHITE
        

The statement WRITE ^|"M1.GLD"|A is equivalent to WRITE ^A.

Specifying separate Global Directories does not always translate to using separate databases.

Example:

        GTM>WRITE ^|"M1.GLD"|A,!,^|"M2.GLD"|A,!,^|"M3.GLD"
        |A,!
        THIS IS ^A IN DATABASE WHITE
        THIS IS ^A IN DATABASE BLUE
        THIS IS ^A IN DATABASE WHITE
        

In this example, the WRITE does not display ^A from three GT.M database files. Mapping specified by the Global Directory Editor (GDE) determines the database file to which a Global Directory points.

This result could have occurred under the following mapping:

        ^|"M1.GLD"|A --> REGIONA --> SEGMENTA --> FILE1.DAT
        ^|"M2.GLD"|A --> REGIONA --> SEGMENT1 --> FILE2.DAT
        ^|"M3.GLD"|A --> REGION3 --> SEGMENT3 --> FILE1.DAT
        

For more information on Global Directories, refer to the "Global Directory Editor" chapter of the GT.M Administration and Operations Guide.