[comp.lang.modula3] Proposal for change in the RTMisc interface

nr@atomic.Princeton.EDU (Norman Ramsey) (04/03/91)

The current RTMisc interface handles ``cleanup on exit'' as follows:

  TYPE Exitor <: REFANY;
  
  PROCEDURE RegisterExitor (p: PROCEDURE (n: INTEGER)): Exitor;
  (* Registers the procedure p to be executed when Exit is called; it is passed
     the argument of Exit.
     The registered procedures are executed in the reverse order. *)
  
  PROCEDURE UnregisterExitor (e: Exitor);
  (* removes e's procedure from the registered set. *)
  
  PROCEDURE Exit (n: INTEGER);
  (* call the registered exitors and terminate the program with status 'n' *)
  
I propose the following change, to make it possible for exitors to
have more state:

  TYPE Exitor <: REFANY;
  TYPE ExitorClosure = OBJECT METHODS apply(n:INTEGER); END;
  
  PROCEDURE RegisterExitor (p: ExitorClosure): Exitor;
  (* Registers the procedure p to be executed when Exit is called; it is passed
     the argument of Exit.
     The registered procedures are executed in the reverse order. *)
  
  PROCEDURE UnregisterExitor (e: Exitor);
  (* removes e's procedure from the registered set. *)
  
  PROCEDURE Exit (n: INTEGER);
  (* call the registered exitors and terminate the program with status 'n' *)


Comments?
-- 
Norman Ramsey
nr@princeton.edu