|
|
|
|
|
|
|
☜ | SET1995 Version of ANSI (Equivalent to Current ISO Version) of Standard | ☞ |
8.2.18 Set
S[ET] postcond SP L setargument
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.
- One of the following two operations is performed:
- 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.
- 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.
- 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.
- One of the following four operations is performed.
- 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).
- 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:
- m > n or n < 1.
The glvn is not changed and does not change the
naked indicator.
- 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.
- m–1 '> k < n.
The value in glvn is replaced by
$P(s,d,1,m–1)_F(min(m–1,1))_t.
- 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).
- 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:
- m > n or n < 1.
The glvn is not changed and does not change the
naked indicator.
- n '< m–1 > k.
The value in glvn is replaced by
s_$J("",m–1-k)_t.
- m–1 '> k < n.
The value in glvn is replaced by
$E(s,1,m–1)_t.
- 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.
- If the left-hand side of the Set is a
setev, one of the following two operations is
performed:
- 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.
- 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:
- The intexpr to the right of the = is
evaluated.
- The value of the intexpr is given to the
special intrinsic variable on the left of the = with the
following restrictions and affects:
- 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.
- 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):
- references to glvns in exprs in
arguments or subscripts of setlefts;
- references to glvns in the expr
on the righthand side of the = sign;
- references to glvns in the
setdestination.
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)