[M3devel] subrange value not constant?

Tony Hosking hosking at cs.purdue.edu
Tue May 19 23:48:34 CEST 2009


min is a variable argument to Sort.  You should use an open array  
argument to Sort:  ARRAY OF INTEGER.  Modula-3 does not support alloca  
style of allocation.  You need to allocate the count array in the  
heap.  count := NEW(ARRAY OF INTEGER, NUMBER(a)).


On 20 May 2009, at 07:32, Martin Bishop wrote:

> I've written this procedure (an implementation of counting sort):
>
> PROCEDURE Sort(VAR a: ARRAY OF INTEGER; min, max: INTEGER) =
> VAR count := ARRAY [min..max] OF INTEGER {0, ..};
>     z := 0;
> BEGIN
>   FOR i := FIRST(a) TO LAST(a) DO
>     count[i - min] := count[i - min] + 1;
>   END;
>   FOR i := min TO max DO
>     WHILE count[i - min] > 0 DO
>       a[z] := i;
>       INC(z);
>       count[i - min] := count[i - min] - 1;
>     END;
>   END;
> END Sort;
>
> However, when I try to compile I get:
>
> "../Counting.m3", line 8: subrange lower bound is not constant
> "../Counting.m3", line 8: subrange upper bound is not constant
>
> Line 8 is:
>
> VAR count := ARRAY [min..max] OF INTEGER {0, ..};
>
> I don't see what's wrong?




More information about the M3devel mailing list