Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site gatech.UUCP Path: utzoo!linus!philabs!cmcl2!floyd!clyde!akgua!gatech!spaf From: spaf@gatech.UUCP (Gene Spafford) Newsgroups: net.lang Subject: Re: Strong Typing and Ignorance Message-ID: <2723@gatech.UUCP> Date: Thu, 8-Dec-83 01:47:58 EST Article-I.D.: gatech.2723 Posted: Thu Dec 8 01:47:58 1983 Date-Received: Sat, 10-Dec-83 01:37:37 EST References: <2892@utcsrgv.UUCP> <137@csd1.UUCP>, <1457@rlgvax.UUCP> Organization: Georgia Tech School of ICS, Atlanta Lines: 48 From: guy@rlgvax.UUCP Newsgroups: net.lang Subject: Re: Strong Typing and Ignorance Message-ID: <1457@rlgvax.UUCP> [...] procedure foo(var i, j : integer); var k : 2 .. 12; begin { ASSERT 1 <= i <= 6, 1 <= j <= 6 } k = i + j; end if the assertion in question is true, 2 <= i+j <= 12 so the assignment will always be valid. Yes, that assertion will make the result true in all cases, but it is not a completely correct assertion. That is, input of the values -37 and 40 for i and j would also produce a correct result, as would 0 and 3 (for example). Depending on how integer arithmetic is defined and implemented, it is entirely possible that the values -40000 and -25532 could also produce an answer in range (assuming 16 bit, 2's complement, with no error triggered for underflow). The question concerns the exact type, and associated semantics, used in the evaluation of the expression on the right hand side. Is it done in the mode of the LHS? Or is it done in the mode of the "most precise" (whatever that is) mode on the RHS? In general, I see the assignment operator as a function implying type conversion, and the operation on the right is done according to whatever semantics apply to those variables -- without regard to the LHS. That way, definition of a subrange is a restriction on the returned value of the assignment function, akin to the restrictions in some languages about assigning reals to integers, or defining the range on a trig function. Look at it this way -- if the assignment statement was i := i +j; would that assertion still be valid? -- Off the Wall of Gene Spafford School of ICS, Georgia Tech, Atlanta GA 30332 CSNet: Spaf @ GATech ARPA: Spaf.GATech @ CSNet-Relay uucp: ...!{akgua,allegra,rlgvax,sb1,unmvax,ulysses,ut-sally}!gatech!spaf