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

SET

1995 Version of ANSI (Equivalent to Current ISO Version) of Standard

8.2.18 Set

S[ET] postcond SP L setargument

    setargument::=

setdestination = expr
@ expratom V L setargument


    setdestination::=

setleft
( L setleft )


    setleft::=


leftrestricted
leftexpr
glvn



    leftrestricted::=



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




    leftexpr::=


setpiece
setextract
setev



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

$EC[ODE]
$ET[RAP]


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. If the portion of the setargument to the left of the = does not consist of $X or $Y then 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, the glvn that is the first argument of the setpiece 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 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.
  3. One of the following four 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 $P(s,d,1,m–1)_F(min(m–1,1))_t.
      4. Otherwise,
        The value in glvn is replaced by $P(s,d,1,m–1)_F(min(m–1,1))_t_d_$P(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 mth through the nth 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_$J("",m–1-k)_t.
      3. m–1 '> k < n.
        The value in glvn is replaced by $E(s,1,m–1)_t.
      4. Otherwise,
        The value in glvn is replaced by $E(s,1,m–1)_t_$E(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, the current value of $ECode is replaced by the value of expr. If the value of the expr is the empty string, $STack($STack,"ECODE") returns the empty string as do all forms of the function $STack($STack+n) for all values of n greater than 0. Note that if the value of $ECode becomes non-empty, an error trap will be invoked.
      2. If the setev is $ETrap, the current value of $ETrap is replaced by the value of expr.

If the portion of the setargument to the left of the = is a $X or a $Y then the execution of the setargument occurs in the following order:

  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.

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 arguments 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.
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.

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

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