[M3devel] Implementing the "Singleton pattern" in Modula-3

Mika Nystrom mika at async.caltech.edu
Mon Apr 6 22:31:57 CEST 2009


Tony, Jay, you two seem to be most knowledgeable about this.

Let's say I wanted to implement the "singleton pattern" in
Modula-3.  At present there seems to be no way of doing this.

What about changing RTAllocator.callback as follows (or adding
another callback):

VAR callback : PROCEDURE(r : REFANY) : REFANY := NIL;

(* If non-NIL, the allocator calls "callback(r)" just before returning
   a new traced reference "r" and instead returns the result of callback(r).  
   See "RTAllocStats" for an example client.  It is a checked runtime error
   for the typecode of r to differ from the typecode of the return value of
   callback(r).  *)

      Mika







More information about the M3devel mailing list