Modula-2 / Modula-3

General

Modula-2
Modula-3
GNU Modula-2 (gm2)
Critical Mass Modula-3 (CM3)

Tutorials

Libraries

FAQ

Question

$ gm2 -g hello.mod
/usr/bin/ld: cannot find -lpth
collect2: error: ld returned 1 exit status

Answer

[Gm2] Re: still won’t compile and link

$ sudo apt-get install libpth-dev
[...]
The following NEW packages will be installed:
  libpth-dev libpth20
[...]

$ gm2 -g hello.mod
<no output>

Question

$ gm2 -o hello -g hello.mod
failed to find definition module InOut.def

Answer

Every compiler has other libraries with exactly the same functions/procedures:

  • InOut (ulm)
  • Terminal2
  • StrIO
$ ls -la /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/
total 48
drwxr-xr-x 8 root root  4096 Jan  7 13:43 .
drwxr-xr-x 8 root root  4096 Jan  7 13:43 ..
drwxr-xr-x 2 root root  4096 Jan  7 13:43 cor
drwxr-xr-x 2 root root 12288 Jan  7 13:43 iso
drwxr-xr-x 2 root root  4096 Jan  7 13:43 log
drwxr-xr-x 2 root root  4096 Jan  7 13:43 min
drwxr-xr-x 2 root root  4096 Jan  7 13:43 pim
drwxr-xr-x 2 root root 12288 Jan  7 13:43 ulm
$ sed -i -e 's/InOut/StrIO/g' hello.mod
$ gm2 -o hello -g hello.mod
<no output>

or

$ gm2 -flibs=ulm,pim -o hello -g hello.mod

Question

There is no procedure “RealRandomNumbers”

Answer

Only in “Stony Brook Modula-2” or the successor “ADW Modula-2” there is a procedure “RealRandomNumbers”.
Stony Brook Modula-2 Development System
Stony Brook Software Home Page
modula2.org: Stony Brook Modula-2

There is a library to generate random numbers:
Ulm’s Modula-2 Library: RandomGenerator

$ grep -r Random /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/RandomNumber.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/log/Random.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/ulm/RandomGenerator.def

Question

There are no string procedures (like Length or IntToStr).

Answer

ISO Modula-2 Modules Reference

Input/Output

String Conversions

The string conversions library allows the conversion of the values of numeric data types to and from character string representations. The modules WholeStr, RealStr, and LongStr provide simple high-level facilities for converting to and from strings and whole number and real number data types. Low-level facilities are provided by the corresponding modules WholeConv, RealConv, and LongConv. Common data types and values that are used in the definition modules are defined by the module ConvTypes.

FROM WholeStr   IMPORT IntToStr, CardToStr;
FROM RealStr    IMPORT RealToStr;

FROM 

Use additional libraries (= modules)

$ grep -r "PROCEDURE Length" /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/M2RTS.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/Strings.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/RealConv.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/log/Strings.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/ulm/M2RTS.mod

$ gm2 -flibs=iso,pim -g -c MyLib.mod
$ grep -r "PROCEDURE StrToInt" /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
iso/WholeStr.def:PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER;
iso/WholeStr.mod:PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER;
ulm/StrToNum.mod:   PROCEDURE StrToInt(str: ARRAY OF CHAR; VAR integ: INTEGER): BOOLEAN;
ulm/StrToNum.def:   PROCEDURE StrToInt(str: ARRAY OF CHAR; VAR integ: INTEGER): BOOLEAN;
pim/NumberIO.mod:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; FORWARD ;
pim/NumberIO.mod:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ;
pim/NumberIO.def:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ;

$ vi Main.mod
[...]
FROM WholeStr   IMPORT IntToStr, CardToStr;
[...]

$ gm2 -flibs=iso,pim -g -c Main.mod

Question

How to use files

Answer

log/InOut.def
ulm/InOut.def
Files.def

Modula-2 “cat” in ISO-style

iso/StreamFile
iso/ChanConsts
iso/STextIO
iso/TextIO
iso/IOConsts
iso/IOChan

Dynamic Strings

pim/DynamicStrings.def

DEFINITION MODULE DynamicStrings ;

(* Description: provides a dynamic string type and common methods. *)

Leave a Reply

Your email address will not be published. Required fields are marked *