[M3devel] Integer literals

Tony Hosking hosking at cs.purdue.edu
Sun Jan 10 21:23:28 CET 2010


One thing I've really struggled with over the introduction of LONGINT is the need for distinct literal forms.  This strikes me as odd, since literals are really just ways of writing values, rather than stating anything about how they should be represented.
(Yes, I know that the REAL/LONGREAL/EXTENDED literals are all distinct, but they really do have incompatible value representations).

It strikes me that with checked assignability for INTEGER/LONGINT we could also potentially treat integer literals as essentially "untyped" (neither INTEGER nor LONGINT). (I still strongly resist going the route of having mixed type operands for arithmetic...)

Here's how things would work with subrange types.

A subrange written as currently

[lo .. hi]

would by default be assumed to have base type INTEGER.  The constants lo/hi must both be in range for INTEGER.

A subrange with base type LONGINT would be written explicitly:

[lo .. hi] OF LONGINT

The constants lo/hi must both be in range for LONGINT.

We could also support the form:

[lo .. hi] OF INTEGER

just for consistency though the "OF INTEGER" qualification would be unnecessarily verbose.

Here we are allowing the programmer to state explicitly what the base type of the subrange should be.

Literals would be be range-checked when used as arithmetic operands or in assignment, with compile-time checks that they are in range ("compatible") with the types of the other operands or the destination of the assignment.

Antony Hosking | Associate Professor | Computer Science | Purdue University
305 N. University Street | West Lafayette | IN 47907 | USA
Office +1 765 494 6001 | Mobile +1 765 427 5484




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100110/6a0b1439/attachment-0001.html>


More information about the M3devel mailing list