It is currently Thu Mar 28, 2024 3:23 pm


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sat Feb 01, 2014 2:31 pm 
Site Admin
User avatar

Joined: Mon Nov 01, 2010 1:58 pm
Posts: 205
Location: Seattle, Washington
Real Name: Frederick D. S. "Rick" Marshall
Began Programming in MUMPS: 15 Jun 1984
Ambiguities exist for SET $X and SET $Y.

MUMPS 1995 clause 8.2.18 SET says:

Quote:
b) 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.


In other words, a set leftrestricted operation is expected to perform whatever type coercion is needed to produce an appropriate value for the target. This makes intuitive sense, since MUMPS prefers type coercion over errors wherever possible.

In clause 7.1.4.10 Intrinsic special variable names svn, $X and $Y are defined as containing nonnegative integers:

Quote:
$X $X has a nonnegative integer value which approximates the value of the horizontal co- ordinate of the active position on the current device. It is initialized to zero by any control-function or format that involves a move to the start of a line.

...

$Y $Y has a nonnegative integer value which approximates the value of the vertical co-ordinate of the active position on the current device. It is initialized to zero by any control-function or format that involves a move to the start of a page.


In clause 7.1.4.6 Integer interpretation, rules are given for coercing any string into an integer. So far so good, but we have no rules for interpreting an integer into a nonnegative integer, so what should happen if someone writes SET $X=-10? Should $X be assigned the value 10 or 0 or should an error condition arise? I don't know. The only thing I know for sure is that it should not be assigned the value -10.

David Wicksell and I were chatting about timeouts and the Hang command, which led me to discover this bit of text in the definition of timeouts, in clause 8.1.5 · Command timeout timeout:

Quote:
If the optional timeout is present, the value of numexpr must be nonnegative. If it is negative, the value 0 is used.


So here is some precedent about how to coerce numbers into nonnegative numbers. We might apply this to $X and $Y to pin down their coercion rules, as a casual interpretation. We also might consider a new MDC proposal to move these rules for type coercion into nonnegative numbers (or nonnegative integers) out of this time-out section and into clause 7.1.4 · Expression item expritem, where the rules for type coercion is given. The definitions of $X and $Y could then specifically tie their definition to a nonnegative integer data type, to remove all ambiguity about the rules governing type coercion when interpreting SET $X or SET $Y. Likewise, the definition of timeouts could then just reference those type coercion rules.

This is by no means an authoritative statement abut how it should be done, just an idea for a proposal.

Eugene, Ray, and other implementors, what do you think? How do you handle something like SET $X=-42 currently?

Everyone else, do you have questions, comments, or criticisms about this approach to clarifying SET $X and SET $Y?

_________________
Frederick D. S. "Rick" Marshall, VISTA Expertise Network, 819 North 49th Street, Suite 203, Seattle, Washington 98103, (206) 465-5765, rick dot marshall at vistaexpertise dot net
"The hidden harmony is best." - Heraclitus of Ephesus


Top
Offline Profile  
 
 Post subject: Re: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sat Feb 01, 2014 3:44 pm 
User avatar

Joined: Wed Jul 20, 2011 11:49 am
Posts: 9
Location: Russia, Moscow
Real Name: Eugene Karataev
Began Programming in MUMPS: 10 Mar 1997
> How do you handle something like SET $X=-42 currently?

Here must be raising an error M43.


Top
Offline Profile  
 
 Post subject: Re: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sat Feb 01, 2014 4:58 pm 
Site Admin
User avatar

Joined: Mon Nov 01, 2010 1:58 pm
Posts: 205
Location: Seattle, Washington
Real Name: Frederick D. S. "Rick" Marshall
Began Programming in MUMPS: 15 Jun 1984
Eugene, you are right. I missed this, from the definition of the Set command (further down from where I was reading:

Quote:
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:

a) The intexpr to the right of the = is evaluated.

b) 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.


Thank you, Eugene. I had missed this, and it makes it clear that the rules for SET $X and SET $Y are clear.

I did find some small cleanup items in this text we might do instead. For example, "affects" instead of effects" above in (b) is a spelling error. There are also two formalization errors, one quoted above, the other just the same but occurring higher up in the SET definition; where it now reads "If the portion of the setargument to the left of the = is a $X or a $Y" it should instead read "If the setleft is a $X or a $Y". As worded, it would not apply in cases like SET (VARIABLE,$X)=12, since (VARIABLE,$X) contains $X but does not equal it.

Accordingly, I suggest doing a small cleanup proposal based on these three minor corrections instead, since the type issue I was concerned about turns out to be a nonissue.

_________________
Frederick D. S. "Rick" Marshall, VISTA Expertise Network, 819 North 49th Street, Suite 203, Seattle, Washington 98103, (206) 465-5765, rick dot marshall at vistaexpertise dot net
"The hidden harmony is best." - Heraclitus of Ephesus


Top
Offline Profile  
 
 Post subject: Re: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sat Feb 01, 2014 10:14 pm 
User avatar

Joined: Mon Nov 01, 2010 3:33 pm
Posts: 104
Location: Australia
Real Name: Ray Newman
Began Programming in MUMPS: 01 Jul 1976
I missed the error bit when implementing SET $X/$Y also. I feel that the coercion is a more MUMPS like method and SET $X=-42 gives $X the value of 0.

Ray


Top
Offline Profile  
 
 Post subject: Re: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sat Feb 01, 2014 10:44 pm 
Site Admin
User avatar

Joined: Mon Nov 01, 2010 1:58 pm
Posts: 205
Location: Seattle, Washington
Real Name: Frederick D. S. "Rick" Marshall
Began Programming in MUMPS: 15 Jun 1984
Ray, unfortunately, it looks like coercing a negative integer to zero, however Mumpsy, is nonstandard. MUMPS 1995 requires error condition M43 here, and I cannot change that even with a new MDC proposal, because it would violate the MDC rule about preserving backward compatibility.

_________________
Frederick D. S. "Rick" Marshall, VISTA Expertise Network, 819 North 49th Street, Suite 203, Seattle, Washington 98103, (206) 465-5765, rick dot marshall at vistaexpertise dot net
"The hidden harmony is best." - Heraclitus of Ephesus


Top
Offline Profile  
 
 Post subject: Re: Possible New Proposal: SET $X and $Y Clarification
PostPosted: Sun Mar 16, 2014 12:40 am 
User avatar

Joined: Mon Nov 01, 2010 1:39 pm
Posts: 51
Real Name: John Willis
Began Programming in MUMPS: 01 Apr 2010
Rick,

I have updated FreeM to comply with this bit of the standard:

Code:
FreeM> SET $X=-55
 
>> <M43: invalid range value ($X, $Y)>^%LOGIN
>> SET $X=-55
            ^
FreeM> SET $Y=-21
 
>> <M43: invalid range value ($X, $Y)>^%LOGIN
>> SET $Y=-21
            ^


We were coercing negative values to zero before.

_________________
John Willis, Founder
Coherent Logic Development
http://youngmumpster.wordpress.com/
jwillis@coherent-logic.com


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net