gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions about behavior observed in gm2


From: Benjamin Kowarsch
Subject: Re: Questions about behavior observed in gm2
Date: Mon, 4 Dec 2023 15:22:48 +0900

Welcome back to Modula-2

On Mon, 4 Dec 2023 at 14:49, Jack Perry wrote:

I would be very grateful for any insight people can give on these; I'm pretty sure they're easy to answer!

1. If I define the type `Constraints = [1..140]` and the variable `Idx: Constraints`, then if I increment `Idx` repeatedly until `Idx = MAX(Constraints) + 1`, should that be a run-time error? It is in Ada, but not in Modula-2 w/gm2.

It should cause a runtime fault in Modula-2 as well. However, some compilers permit such runtime checks to be turned on and off by compiler switches and if the default is 'off' it would have to be explicitly turned on. I am not sure what the intended default behaviour in GM2 is. Gaius (the developer of GM2) can clarify this.

4. There's no way to obtain a subscript of an array by "slicing", is there? For example,

      VAR
         A: ARRAY [1..10] OF CHAR;
     BEGIN
         DoSomethignWith(A[3..5]);

Array slicing is not a feature in PIM2/3/4 and ISO M2.

FYI, it is a feature in M2 R10 though.

array[n..m]  yields slice with elements of indices n to m
array[n..-1]  yields slice with element of index n to last element
array[n..-2]  yields slice with element of index n to second last element
etc

https://github.com/m2sf/m2bsk/wiki/Language-Specification-(7)-:-Operators-and-Expressions#designation-operations

There's also insertion and concatenation.

array[n..] := { foo, bar, baz }  inserts elements foo, bar and baz at index n
array1 & array2  yields concatenation product of array1 and array2

https://github.com/m2sf/m2bsk/wiki/Language-Specification-(7)-:-Operators-and-Expressions#collection-operations

Unfortunately though, the compiler is still work in progress and whilst Gaius had expressed his intent for support in GM2 before, this hasn't come to fruition yet either. I hope to find some time again working on the compiler in the coming year. Eventually we'll get there, but for now there is no array slicing in any working M2 compiler.

regards
benjamin (who is now rather busy running an artisan bakery)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]