ModulaTor logo, 7.8KB

The ModulaTor

Oberon-2 and Modula-2 Technical Publication

Ubaye's First Independent Modula-2 & Oberon-2 Journal! Nr. 78, Apr-1999


A minimal self-reproducing program written in Oberon

by Peter Ryser, ETH Zurich

2nd edition, 11-May-1999

A program that prints out its source code when run

The following program should be minimal in respect to the size of the generated code. Please note that the module "M" must be unloaded from the memory to work correctly.


MODULE M;
 IMPORT O:=Out;
 CONST
  T=";PROCEDURE c*;BEGIN O.Char(22X);O.String(T) END c;BEGIN O.String('MODULE M;IMPORT O:=Out;CONST T=');c END M.";

 PROCEDURE c*;
 BEGIN
  O.Char(22X);O.String(T)
 END c;

BEGIN
 O.String('MODULE M;IMPORT O:=Out;CONST T=');
 c
END M.

To start the program and view the output click here: M.c

To start the program again, first unload it with the command System.Free M~


Another minimal self-reproducing program written in Oberon

by Hans Klaver, The Netherlands.

Striving for simplicity pays off.

The following program Print works under the Oberon System (S3 and V4) and prints itself to the System.Log, when its exported command Me is activated.


MODULE Print; (* Hans Klaver, 09-May-1999 *)
(** To execute middle-click Print.Me **)

  IMPORT In, Out;

  PROCEDURE Me*;
    VAR ch: CHAR;
  BEGIN
    In.Open;
    In.Char(ch);
    WHILE In.Done DO
      Out.Char(ch);
      In.Char(ch)
    END
  END Me;

END Print.Me*

Which is evidence that even in "demented" programming tasks Oberon offers a perfectly simple solution!

It is interesting to note that the command Print.Me* also prints any changes made in the program text, even before these are stored to disk.


[Ed. note] All programs published with authorization of the respective authors.

IMPRESSUM: The ModulaTor is an unrefereed journal. Technical papers are to be taken as working papers and personal rather than organizational statements. Items are printed at the discretion of the Editor based upon his judgement on the interest and relevancy to the readership. Letters, announcements, and other items of professional interest are selected on the same basis. Office of publication. The Editor of The ModulaTor is Günter Dotzel; he can be reached at mailto:[email deleted due to spam]

Most of the ModulaTor back-issues are available from http://www.modulaware.com/


[ Home | Site_index | Legal | OpenVMS_compiler | Alpha_Oberon_System | ModulaTor | Bibliography | Oberon[-2]_links | Modula-2_links | General interesting book recommendations ]
© (1999) by modulaware.com
Created 11-Jun-1999