| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| set i=1,j=2,k=3 if i<j&k>j 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 |
|
#2
| |||
| |||
| 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. "Duke Normandin" <dukeofperl@ml1.net> wrote in message news URRj.3093$PM5.3083@edtnps92...> 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 |
|
#3
| |||
| |||
| On 2008-04-30, Maury Pepper <mpepper_scram_spam@ieee.org> 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@ml1.net> wrote in message > news URRj.3093$PM5.3083@edtnps92...>> 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 |
|
#4
| |||
| |||
| In message <pURRj.3093$PM5.3083@edtnps92>, Duke Normandin <dukeofperl@ml1.net> writes >set i=1,j=2,k=3 >if i<j&k>j 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...... Left to right operator precedence. i<j is true so evaluated to 1 1&k is true so evaluates to 1 1>j is false so yes is not printed. to obtain the correct result the conditions should be in parentheses if (i<j)&(j>j) write yes. However an alternate would be if i<j,k>j write yes This is possibly preferred in that the command is broken into two commands, and the second one only executed if the first one is true. The reason for the preference is performance. The second condition is only evaluated if the first is true, so by putting the least likely condition first one can optimise the code. Optimisation should only be done when the code retains clarity, and when it is executed sufficiently often to justify the work. -- Philip Gage |
|
#5
| |||
| |||
| You are correct. Normally, I would write: if i<j&(k>j) write ... but the & provides an opportunity 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 naked 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 naked references!) "Duke Normandin" <dukeofperl@ml1.net> wrote in message news:W8ZRj.3383$XI1.311@edtnps91... > On 2008-04-30, Maury Pepper <mpepper_scram_spam@ieee.org> 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@ml1.net> wrote in message >> news URRj.3093$PM5.3083@edtnps92...>>> 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 |
|
#6
| |||
| |||
| If PG is forbidden, let me comment. Naked references are at best a daft invention and at worst just plain evil, and are to be avoided at all costs. Stick to explicit global references or you'll end up with an incomprehensible, unmaintainable mess. I'm sure someone somewhere will wade in with a wall of flame to extol their arcane virtues but I've never encountered a single situation in 28 years where they made any sense whatsoever. On Wed, 30 Apr 2008 10:36:19 -0500, "Maury Pepper" <mpepper_scram_spam@ieee.org> wrote: >You are correct. Normally, I would write: if i<j&(k>j) write ... but the & >provides an opportunity 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 naked >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 naked references!) > > > >"Duke Normandin" <dukeofperl@ml1.net> wrote in message >news:W8ZRj.3383$XI1.311@edtnps91... >> On 2008-04-30, Maury Pepper <mpepper_scram_spam@ieee.org> 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@ml1.net> wrote in message >>> news URRj.3093$PM5.3083@edtnps92...>>>> 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 --- Rob Tweed Company: M/Gateway Developments Ltd Registered in England: No 3220901 Registered Office: 58 Francis Road,Ashford, Kent TN23 7UR Web-site: http://www.mgateway.com SlipstreamUSA: April 2, Renaissance Hotel, Orlando http://www.OutOfTheSlipstream.com |
|
#7
| |||
| |||
| On 2008-04-30, Maury Pepper <mpepper_scram_spam@ieee.org> wrote: > You are correct. Normally, I would write: if i<j&(k>j) write ... but the & > provides an opportunity 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 naked > 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 naked references!) I understand everything you've said. However, would you explain what a "naked reference" is -- I have no clue what it refers to. -- Duke Normandin |
|
#8
| |||
| |||
| On 2008-04-30, Rob Tweed <rtweed@mgateway.com> wrote: > If PG is forbidden, let me comment. Naked references are at best a What do you mean by PG? > daft invention and at worst just plain evil, and are to be avoided at > all costs. Stick to explicit global references or you'll end up with > an incomprehensible, unmaintainable mess. I'm sure someone somewhere > will wade in with a wall of flame to extol their arcane virtues but > I've never encountered a single situation in 28 years where they made > any sense whatsoever. I believe you! Once I know what "naked references" are, I'll be in a better position to judge for myself. -- Duke Normandin |
|
#9
| |||
| |||
| On 2008-04-30, Philip Gage <philip@junk.pgage.demon.co.uk> wrote: > In message <pURRj.3093$PM5.3083@edtnps92>, Duke Normandin ><dukeofperl@ml1.net> writes >>set i=1,j=2,k=3 >>if i<j&k>j 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...... > Left to right operator precedence. > i<j is true so evaluated to 1 > 1&k is true so evaluates to 1 > 1>j is false so yes is not printed. > to obtain the correct result the conditions should be in parentheses > > if (i<j)&(j>j) write yes. > > However an alternate would be > > if i<j,k>j write yes > > This is possibly preferred in that the command is broken into two > commands, and the second one only executed if the first one is true. > > The reason for the preference is performance. The second condition is > only evaluated if the first is true, so by putting the least likely > condition first one can optimise the code. > > Optimisation should only be done when the code retains clarity, and when > it is executed sufficiently often to justify the work. Thanks for the great explanation! What is _your opinion_ of "naked references" -- if you dare to go there. ![]() -- Duke Normandin |
|
#10
| |||
| |||
| "Duke Normandin" <dukeofperl@ml1.net> wrote in message news:0waSj.3316$PM5.2929@edtnps92... > On 2008-04-30, Rob Tweed <rtweed@mgateway.com> wrote: >> If PG is forbidden, let me comment. Naked references are at best a > > What do you mean by PG? See: http://en.wikipedia.org/wiki/Peanut_gallery and: http://ask.yahoo.com/ask/20050720.html > >> daft invention and at worst just plain evil, and are to be avoided at >> all costs. Stick to explicit global references or you'll end up with >> an incomprehensible, unmaintainable mess. I'm sure someone somewhere >> will wade in with a wall of flame to extol their arcane virtues but >> I've never encountered a single situation in 28 years where they made >> any sense whatsoever. > > I believe you! Once I know what "naked references" are, I'll be in a > better position to judge for myself. > -- > Duke Normandin See: http://71.174.62.16/Demo/AnnoStd "The prefix ^ uniquely denotes a global variable name. A global variable name is either unsubscripted or subscripted; if it is subscripted, any number of subscripts separated by commas is permitted. Except where otherwise specified, a subscript may not equal the empty string. An abbreviated form of subscripted gvn is permitted, called the naked reference, in which the prefix is present but the environment, name and an initial (possibly empty) sequence of subscripts is absent but implied by the value of the naked indicator. An unsubscripted occurrence of gvn may carry a different value from any subscripted occurrence of gvn." If, instead of using naked reference for my example, I had used a function with side-effects, it would probably have provoked a similar rant. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.