[M3devel] subrange value not constant?

Martin Bishop martinbishop at bellsouth.net
Thu May 21 01:19:57 CEST 2009


By the way, in case anyone cares, here's the proper code:

PROCEDURE Sort(VAR a: ARRAY OF INTEGER; min, max: INTEGER) =
  VAR range := max - min + 1;
      count := NEW(REF ARRAY OF INTEGER, range);
      z := 0;
  BEGIN
    FOR i := FIRST(a) TO LAST(a) DO
      count[a[i] - min] := count[a[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;

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