Examples of Set

Example:

        GTM>KILL SET a="x",(b,c)=1,@a="hello" ZWRITE
        a=x
        b=1
        c=1
        x="hello"
        GTM>
        

The KILL command deletes any previously defined local variables. The SET command has three arguments. The first shows a simple direct assignment. The second shows the form that assigns the same value to multiple variables. The third shows atomic indirection on the left of the equal sign. The ZWRITE command displays the results of the assignments.

Example:

          GTM>SET ^(3,4)=^X(1,2)
        

Because GT.M evaluates the right-hand side of the equal sign before the left-hand side within a SET argument, the right-hand expression determines the naked reference indicator prior to evaluation of the left-hand side. Therefore, this example assigns ^X(1,3,4) the value of ^X(1,2).

Example:

        GTM>KILL x SET $P(x,"^",3)="piece 2" ZWRITE x
        x="^^piece 2"
        GTM>
        

This SET demonstrates a "setpiece" and shows how SET generates missing delimiters when required. For more information on syntax for $PIECE(), refer to the "Functions" chapter in this manual.

Example:

        GTM>SET x="I love hotdogs"
        GTM>SET $EXTRACT(x,3,6)="want"
        GTM>WRITE x
        I want hotdogs
        GTM>SET $EXTRACT(x,7)=" many "
        GTM>WRITE x
        I want many hotdogs
        GTM>
        

The SET $EXTRACT command replaces and extracts the specified characters with the value of the expression on the right hand side of the equal-sign (=).