Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

SET

Draft MDC Standard

8.2.30 Set

S[ET] postcond SP L setargument

    setargument::=

setdestination = expr
@ expratom V L setargument


    setdestination::=

setleft
( L setleft )


    setleft::=



leftrestricted
leftexpr
glvn
owproperty




    leftrestricted::=




$D[EVICE]
$K[EY]
$R[EFERENCE]
$X
$Y





    leftexpr::=



setpiece
setextract
setev
setqsub




    setpiece::= $P[IECE] ( glvn , expr [ , intexpr1 [ , intexpr2 ] ] )
    setextract::= $E[XTRACT] ( glvn [ , intexpr1 [ , intexpr2 ] ] )
    setev::=

$EC[ODE]
$ET[RAP]


    setqsub::= $QS[UBSCRIPT] (glvn , intexpr )
Editor’s note:
Simply glvn doesn’t seem right to me here: of course, since the value needs to be stored some place, the destination must be a glvn, but the value of that glvn must be one on which $QS[UBSCRIPT] can operate, so,suggest to change this to: glvn V namevalue.
    setdextract::= $DE[XTRACT] ( extracttemplate , L [ recordfieldglvn ] )
    setdpiece::= $DP[IECE] ( piecedelimiter , L [ recordfieldglvn ] )
    recordfieldglvn::= glvn [ : fieldindex ]
Editor’s note:
In the definition of recordfieldglvn, is that colon supposed to be inside or outside the brackets?

See 7.1.2 for the definition of glvn. See 7.1.4.6 for the definition of intexpr.

Set is the general means both for explicitly assigning values to variables, and for substituting new values in pieces of a variable. Each setargument computes one value, defined by its expr. That value is then either assigned to each of one or more variables, or it is substituted for one or more pieces of a variable’s current value. Each variable is named by one glvn.

Each setargument is executed one at a time in left-to-right order. The execution of a setargument occurs in the following order.

  1. One of the following two operations is performed:
    1. If the portion of the setargument to the left of the = consists of one or more glvns, the glvns are scanned in left-to-right order and all subscripts are evaluated, in left-to-right order within each glvn.
    2. If the portion of the setargument to the left of the = consists of a setpiece or a setextract or a setqsub, the glvn that is the first argument of the setpiece or setextract or setqsub is scanned in left-to-right order and all subscripts are evaluated in left-to-right order within the glvn, and then the remaining arguments of the setpiece or setextract or setqsub are evaluated in left-to-right order.
  2. The expr to the right of the = is evaluated. For each setleft, if it is a leftrestricted, the value to be assigned or replaced is truncated or converted to meet the inherent restrictions for that setleft before the assignment takes place. This means that in one Set command, the various setlefts may receive different values. If, however, a leftrestricted is either $X or $Y, the following additional considerations apply:
    1. The intexpr to the right of the = is evaluated.
    2. The value of the intexpr is given to the special intrinsic variable on the left of the = with the following restrictions and affects:
      1. The range of values of $X and $Y are defined in 7.1.4.10. Any attempt to set $X or $Y outside this range specified in 7.1.4.10 is erroneous (ecode = "M43") and the value of $X or $Y will remain unchanged.
      2. Setting $X or $Y changes the value of $X or $Y, respectively, but it does not cause any input or output operation. The purpose is to allow a program to correct the value of $X or $Y following input or output operations whose effect on the cursor position may not be reflected in $X and $Y.
  3. One of the following specific operations is performed.
    1. If the left-hand side of the set is one or more glvns, the value of expr is given to each glvn, in left-to-right order. (See 7.1.2.2 for a description of the value assignment operation).
    2. For each setleft that is a setpiece, of the form $Piece( glvn , d , m , n ), the value of expr replaces the mth through the nth pieces of the current value of the glvn, where the value of d is the piece delimiter. Note that both m and n are optional. If neither is present, then m = n = 1; if only m is present, then n = m. If glvn has no current value, the empty string is used as its current value. Note that the current value of glvn is obtained just prior to replacing it. That is, the other arguments of setpiece are evaluated in left-to-right order, and the expr to the right of the = is evaluated prior to obtaining the value of glvn.
      Let s be the current value of glvn, k be the number of occurrences of d in s, that is, k = max( 0, $Length( s , d ) - 1), and t be the value of expr. The following cases are defined, using the concatenation operator _ of 7.2.1.1:
      1. m > n or n < 1
        The glvn is not changed and does not change the naked indicator.
      2. n '< m - 1 > k
        The value in glvn is replaced by s_F(m–1-k)_t, where F(x) denotes a string of x occurrences of d, when x > 0; otherwise, F(x) = "". In either case, glvn affects the naked indicator.
      3. m - 1 '> k < n
        The value in glvn is replaced by $Piece(s , d , 1, m - 1) _ F( min( m - 1, 1) ) _ t.
      4. Otherwise,
        The value in glvn is replaced by
        $Piece(s , d , 1, m - 1) _ F( min( m - 1, 1) ) _ t _ d _ $Piece(s , d , n +1, k +1).
    3. For each setleft that is a setextract of the form $Extract( glvn , m , n ), the value of expr replaces the m th through the n th characters of the current value of the glvn. Note that both m and n are optional. If neither is present, then m = n = 1; if only m is present, then n = m. If glvn has no current value, the empty string is used as its current value. Note that the current value of glvn is obtained just prior to replacing it. That is, the other arguments of setextract are evaluated in left-to-right order, and the expr to the right of the = is evaluated prior to obtaining the value of glvn.
      Let s be the current value of glvn, k be the number of characters in s, that is, k = $Length(s), and t be the value of expr. The following cases are defined, using the concatenation operator _ of 7.2.1.1:
      1. m > n or n < 1
        The glvn is not changed and does not change the naked indicator.
      2. n '< m - 1 > k
        The value in glvn is replaced by s _ $Justify("", m - 1 - k ) _ t
      3. m - 1 '> k < n
        The value in glvn is replaced by $Extract( s, 1, m - 1) _ t
      4. Otherwise,
        The value in glvn is replaced by $Extract(s , 1, m - 1) _ t _ $Extract(s , n +1, k ).
      In cases b), c) and d) the naked indicator is affected.
    4. If the left-hand side of the Set is a setev, one of the following two operations is performed:
      1. If the setev is $ECode:
        If the value of expr is the empty string:
        1. The current value of $ECode is replaced by the empty string.
        2. All forms of the two-argument function $STack( $STack + n , ... ) return the empty string for all values of n > 0.
        3. All forms of the function $STack( $STack + n ) return the empty string for all values of n > 0.
        If the value of expr is not the empty string:
        1. If the value of expr does not conform to the format required in section 7.1.4.10.2 for $ECode, the Set of $ECode to the value of the expr is not performed. Instead, an error condition occurs with ecode = "M101".
        2. If the value of expr does conform to the format required in section 7.1.4.10.2 for $ECode:
          1. The current value of $ECode is replaced by the value of expr.
          2. The value of $STack( $STack, "ECODE") is replaced by the value of expr.
          3. The value of $STack( $STack, "PLACE") is replaced to reflect the Set command that is updating $ECode.
          4. The value of $STack( $STack, "MCODE") is replaced to reflect the Set command that is updating $ECode.
          5. An error trap is invoked.
      2. If the setev is $ETrap, the current value of $ETrap is replaced by the value of expr.
    5. For each setleft that is a setqsub of the form $QSubscript(nv , m ), if the value of nv is not a valid namevalue, an error condition occurs with ecode = "M90". Otherwise, let t be the value of expr and nv in the form NAME(s1 , s2 , ... , sn ), considering n to be zero if there are no subscripts. The setleft is modified according to the value of intexpr m as follows:
      1. Values of m less than –1 are reserved for possible future use by the MDC.
      2. If m = –1, the environment is changed to t.
      3. If m = 0, the name is changed to t.
      4. If m > n, the intervening n + 1 through m - 1 subscripts are each set to the empty string and the mth subscript is set to t.
      5. Otherwise, the mth subscript is changed to t.
      If the resulting value of nv is not a valid namevalue, an error condition occurs with ecode = "M90".
      Note that the original and resulting namevalues are not "executed", and will not modify the naked indicator beyond those modifications described at the end of this clause. Note also that the namevalues, while meeting the syntax of a namevalue, might specify a non-existent environment or contain a subscript value (such as the empty string or control characters) which does not meet the requirements of Section II Clause 2.3.3 (Values of subscripts).
    6. If the left-hand side of the Set is an owproperty, the value of the expr is given to the owproperty.
    7. For each setleft that is a setdextract, the expr is used as the starting value, which is partitioned into consecutive $Extract fields using extracttemplate (see $DExtract). Each glvn is assigned its corresponding field extracted from expr. The values corresponding to omitted glvns are ignored. The fieldindex specifies which field is to be assigned to the glvn. If omitted, the next successive field index is assigned. Allthough all elements of the list of recordfieldglvns are optional, at least one recordfieldglvn (not necessarily the first) in the list must be non-empty.
    8. For each setleft that is a setdpiece, the expr is used as the starting value, which is partitioned into consecutive $Piece fields using piecedelimiter (see $DPiece). Each glvn is assigned its corresponding field pieced from expr. The values corresponding to omitted glvns are ignored. The fieldindex specifies which field is to be assigned to the glvn. If omitted, the next successive field index is assigned. Allthough all elements of the list of recordfieldglvns are optional, at least one recordfieldglvn (not necessarily the first) in the list must be non-empty.

The value of the naked indicator may be modified as a side-effect of the execution of a Set command. Events that influence the value of the naked indicator are (in order of evaluation):

  1. references to glvns in exprs in parameters or subscripts of setlefts;
  2. references to glvns in the expr on the righthand side of the = sign;
  3. references to glvns in the setdestination.

References that are defined as scanned in this clause do not affect the naked indicator, whereas references defined as evaluated do.

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 15-Nov-2023, 18:56:15.

For comments, contact Ed de Moel (demoel@jacquardsystems.com)