[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] lib problems
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] lib problems |
Date: |
Mon, 28 Nov 2011 18:35:05 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
"T.D. Telford" <address@hidden> writes:
> Hello,
>
> when I run a simple program (see below), I get the error
>
> gm2 -fiso power.mod
> /home/dtelford/opt/lib/gcc/x86_64-unknown-linux-gnu/4.1.2/gm2/pim/
> StrIO.def:60:1: error: unable to obtain the MIN value for type the ZType
> /home/dtelford/opt/lib/gcc/x86_64-unknown-linux-gnu/4.1.2/gm2/pim/
> StrIO.def:60:1: error: unable to obtain the MAX value for type the ZType
>
> I am running linux Fedora 15 X86_64. I compiled gm2.
>
> Program (from algorithms and data structures):
>
> MODULE Power;
> (*compute decimal representation of negative powers of 2*)
>
> FROM STextIO IMPORT WriteLn, WriteString;
>
> CONST N = 10;
> VAR i, k, r: INTEGER;
> s : ARRAY[1..80] OF CHAR;
> d: ARRAY N OF CARDINAL;
> BEGIN
> FOR k := 0 TO N-1 DO
> WriteString("."); r := 0;
> FOR i := 0 TO k-1 DO
> r := 10*r + d[i]; d[i] := r DIV 2; r := r MOD 2;
> s := " " + CHR(d[i] + ORD("0"));
> WriteString(s )
> END ; (* for *)
> d[k] := 5; WriteString("5"); WriteLn()
> END (* for *)
> END Power.
>
> If I change the IMPORT to
> FROM StrIO IMPORT WriteLn, WriteString;
>
> and compile with gm2 -fpim power.mod
>
> I get the same error.
>
> Ideas?
>
> Regards,
> Doug
Hi Doug,
yes you have a few errors in the code. Your ARRAY declaration is
incorrect (it needs a type rather than a constant) and Modula-2 does not
allow programmers to add (non constant) strings with the operator +
Here is a corrected version (I think!)
MODULE Power;
(*compute decimal representation of negative powers of 2*)
FROM STextIO IMPORT WriteChar, WriteLn, WriteString;
CONST N = 10;
VAR
i, k, r: INTEGER;
s : ARRAY[0..80] OF CHAR;
d: ARRAY [1..N] OF CARDINAL;
BEGIN
FOR k := 0 TO N-1 DO
WriteString("."); r := 0;
FOR i := 0 TO k-1 DO
r := 10*r + d[i]; d[i] := r DIV 2; r := r MOD 2;
WriteChar(CHR(d[i] + ORD("0"))) ;
END ; (* for *)
d[k] := 5; WriteString("5"); WriteLn
END (* for *)
END Power.
regards,
Gaius