[M3devel] still need a branch for longint changes?

Tony Hosking hosking at cs.purdue.edu
Sat Jan 9 06:06:07 CET 2010


So, thinking about things some more I am very much less inclined to believe that mixed operand arithmetic makes any sense, though assignability with run-time range checks seems fine.

With mixed operand arithmetic we get to some very strange places:

LAST(INTEGER) + 1 = FIRST(INTEGER)

is true because of overflow under the standard Modula-3 implementation.

But,

LAST(INTEGER) + 1L = FIRST(INTEGER)

is false because the arithmetic will be performed as LONGINT.

The trivial presence of "1L" instead of "1" has a huge impact on the semantics.  That seems really dangerous.

Much better (if wordier) to require explicit conversion (as currently implemented) to preserve sanity.

Thus,

VAL(LAST(INTEGER), LONGINT) + 1L = VAL(FIRST(INTEGER), LONGINT)

is false, as the programmer rightly expects, because he/she will be explicitly (because of the conversions) aware that LONGINT arithmetic is taking place.

On 8 Jan 2010, at 21:36, Jay K wrote:

> I'm fine with a compromise that requires no runtime checks and users use ORD() to narrow LONGINT to INTEGER.
> And mixed arithmetic is available, and assignability INTEGER to LONGINT.
> I have that implemented. It is a little onerous for Rd/Wr uses, but ok.
>  
>  - Jay
> 
>  
> From: hosking at cs.purdue.edu
> Date: Fri, 8 Jan 2010 21:23:15 -0500
> To: jay.krell at cornell.edu
> CC: m3devel at elegosoft.com
> Subject: Re: [M3devel] still need a branch for longint changes?
> 
> Please hold off on mainline changes.  I don't think we have reached consensus yet...
> 
> The issue remains: mixed arithmetic + checked assignability or not?  I'm leaning towards allowing it, but want to hear from others.
> 
> On 8 Jan 2010, at 21:16, Jay K wrote:
> 
> Still need a branch for longint changes?
>  I doubt what I have is where we are going, though it is a step toward it.
>  Just wait for Tony to implement Rodney's proposal?
>  Or I work on it in a branch? It doesn't look too difficult to at least mostly do. I already have "mixed" stuff compiling and assignability INTEGER to LONGINT. I didn't yet do anything requiring runtime checks, but it's not that hard to do, given that there are already checks for assignment involving only partly overlapping ranges.
> 
> Or maybe just take my stuff to the mainline and then refine/reduce it later?
> 
>  - Jay
> 
> 
> 




More information about the M3devel mailing list