[M3devel] Fwd: Re: A bizarre language quirk
Rodney M. Bates
rodney_bates at lcwb.coop
Sat Mar 24 16:53:26 CET 2018
On 03/21/2018 02:57 PM, Henning Thielemann wrote:
>
> On Wed, 21 Mar 2018, Rodney M. Bates wrote:
>
>> Modula3, 2.6.3 (Designators), concerning subscripting says:
>>
>> An expression of the form a[i_1, ..., i_n] is shorthand for a[i_1]...[i_n].
>
> I think I wrote earlier about this shorthand ...
>
> I found the following problem:
>
> ARRAY OF ARRAY OF Something
>
> is syntactically not quite a 2D-array since as it is written it suggests that the sub-arrays may have different sizes.
It never occurred to me that this syntax could suggest it could be a ragged array, probably because
I was already familiar with the (fixed) array-of-array concept being truly 2D in Pascal and Modula2.
I do see in 2.2.3, in the first paragraph: "The elements all have the same size and the same type,
called the _element type_ of the array", this sentence applying to both fixed and open arrays.
This probably should be clarified, since "size" seems not very precise here. Maybe "element count",
which would be harmlessly redundant in the case of a fixed array.
Two paragraphs later, the definition of array _shape_ seems also to imply the array is not ragged,
but this is perhaps too subtle not to be made explicit somewhere.
> This has practical consequences. It would be no problem to have a 0-by-n array. But Modula-3 fails
>to determine the size of the second dimension of a 0-by-n array, because LAST(a[0]) is a range
>violation in the first dimension.
But a[0] doesn't exist, so what would be a meaningful definition of its size or bounds? Even if you
could somehow define and discover it, you can't do anything else with a[0] either.
The only way I can think of create such a thing would be a zero-length SUBARRAY of an mxn array.
Neither the language nor the compiler disallow a a zero-length SUBARRAY. a could alias the
original mxn array, but only an empty portion of it. Other than copying and passing a around
by reference, there is no meaningful definition of any operation on a.
> _______________________________________________
> M3devel mailing list
> M3devel at elegosoft.com
> https://m3lists.elegosoft.com/mailman/listinfo/m3devel
>
--
Rodney Bates
rodney.m.bates at acm.org
More information about the M3devel
mailing list