A simple example

Here's a simple program composed of a main module, an imported interface and its implementation.

To begin, create a fresh directory for the package and within that directory, a directory for the source files:

    > mkdir hello
    > cd hello
    > mkdir src

Create the following source files in the src directory:

In the file src/Main.m3:

    MODULE Main;
    IMPORT A;
    BEGIN
      A.DoIt ();
    END Main.

In the file src/A.i3:

    INTERFACE A;
    PROCEDURE DoIt ();
    END A.

In the file src/A.m3:

    MODULE A;
    IMPORT Wr, Stdio;

    PROCEDURE DoIt () =
      <*FATAL ANY*>
      BEGIN
        Wr.PutText (Stdio.stdout, "Hello world.\n");
        Wr.Close (Stdio.stdout);
      END DoIt;

    BEGIN
    END A.

In the file src/m3makefile:

    import ("libm3")
    implementation ("Main")
    module ("A")
    program ("foo")

Finally, from the package directory, hello, run m3build. If SRC Modula-3 is installed correctly, it will compile the three source files and link them with the standard libraries. The derived files will be placed in a directory that names the architecture. On an Alpha/AXP machine running OSF, the directory is called ALPHA_OSF. The executable program will be named foo in the derived directory.


[Modula-3 home page]

m3-request@src.dec.com
Last modified on Mon Sep 25 18:23:55 PDT 1995 by heydon 
     modified on Tue Jan  3 07:38:22 PST 1995 by kalsow 
     modified on Thu Jan  7 18:40:57 PST 1993 by muller