You are correct. Normally, I would write: if i<j&(k>j) write ... but the
&
provides an op****tunity to split the if into two parts as:
if i<j,k>j write ... Only if the first argument "i<j" is true does the
second argument "k>j" get evaluated. It has the effect of an AND operator
but there are a couple of differences you should be aware of: 1) it's
faster, and that's generally the appeal of splitting up the expression;
and
2) because later expressions are not evaluated once an expression is
evaluated as false, you may not get the side effects that you were
counting
on. For example:
IF X>Y&$D(^Z(W)) WRITE ^(W)
ELSE WRITE ^(V)
This counts on executing the $D(^Z(W)) in order to set up the ****d
reference. If the & is replace by a comma and X is not greater than Y,
then
the $D won't be executed and the ELSE will likely fail. (Please, no
comments from the PG regarding the use of ****d references!)
"Duke Normandin" <dukeofperl@[EMAIL PROTECTED]
> wrote in message
news:W8ZRj.3383$XI1.311@[EMAIL PROTECTED]
> On 2008-04-30, Maury Pepper <mpepper_scram_spam@[EMAIL PROTECTED]
> wrote:
>> There is no operator precedence in Mumps so the expression "if i<j&k>j"
>> is
>> evaluated as:
>> if (((i<j)&k)>j)
>> Since 1 is less than 2, the first term is true, and "true" has the
value
>> 1.
>> Since 1 & 3 is true, the second term is true, ie = 1.
>> Since 1 is not greater than 2, the third term is false.
>
> I see now! The moral of the story then is:
>
> Put the parentheses where _you_ want/need them and _never_ rely on Mumps
> to do it! ;)
> Thanks!!
>
>> "Duke Normandin" <dukeofperl@[EMAIL PROTECTED]
> wrote in message
>> news:pURRj.3093$PM5.3083@[EMAIL PROTECTED]
>>> set i=1,j=2,k=3
>>>write "yes",!
>>>
>>> i _is_ less than j AND k _is_ greater than j
>>>
>>> so why is _yes_ NOT printed?
>>>
>>> The logical operator & tells me that both relational expressions must
>>> be true in order for the _yes_ to be printed. That's exactly what it
is,
>>> so what am I missing? TIA......
>>> --
>>> Duke Normandin
>
> --
> Duke Normandin


|