From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 13 Dec 91 17:27:22 GMT From: pattis@beaver.cs.washington.edu (Richard Pattis) Subject: Help with Exceptions for Generic Instantiation Message-ID: <1991Dec13.172722.8432@beaver.cs.washington.edu> List-Id: I am trying to write various packages to access/advance-through a sequence of characters (in a file, from a terminal, in an array, etc). I will then be writing genric packages that are instantiated using this information; for example, a lexical analyzer (or regular expression pattern matcher) taking input from a file, a terminal, an array). So far, one example is the following package specification PACKAGE File_Stream IS Open_Error : EXCEPTION; Reset_Error : EXCEPTION; No_More_Data_Error : EXCEPTION; Close_Error : EXCEPTION; TYPE Stream IS LIMITED PRIVATE; PROCEDURE Open (S : IN OUT Stream; Info : IN STRING); PROCEDURE Reset (S : IN OUT Stream); PROCEDURE Get (C : OUT CHARACTER; S : IN OUT Stream); PROCEDURE Close (S : IN OUT Stream); PRIVATE TYPE Stream IS NEW Text_IO.File_Type; END File_Stream; A simple echo utility might then be written as follows: WITH Terminal_Utility, String_Utility; -- My own I/O interfaces GENERIC Message : IN STRING; TYPE Stream IS LIMITED PRIVATE; WITH PROCEDURE Open (S : IN OUT Stream; Info : IN STRING); WITH PROCEDURE Reset (S : IN OUT Stream); WITH PROCEDURE Get (C : OUT CHARACTER; S : IN OUT Stream); WITH PROCEDURE Close (S : IN OUT Stream); PROCEDURE Echo; PROCEDURE Echo IS PACKAGE SU RENAMES String_Utility; PACKAGE TTY RENAMES Terminal_Utility; S : Stream; C : CHARACTER; BEGIN Open(S, TTY.Prompt(Message)); BEGIN LOOP Get(C, S); TTY.Announce(C); END LOOP; EXCEPTION WHEN OTHERS => Close(S); -- No_More_Data_Error END; TTY.Announce(SU.CR); END Echo; The problem is that real programs/packages (beyond the complexity of Echo) will need to individually handle various exceptions by name, yet I cannot find any way to instantiate generics using exceptions. Am I overlooking something obvious or is there something subtle that will help solve my problem? I realize that I could supply generic predicates to "replace" the exceptions, but my question still stands - is there a reasonable way to use exceptions. ------------------------------------------------------------------------------ Richard E. Pattis "Programming languages are like Department of Computer Science pizzas - they come in only "too" and Engineering sizes: too big and too small." University of Washington Seattle, WA 98195 "When debugging, a novice programmer pattis@cs.washington.edu inserts corrective code; an voice: (206) 685-1218 experienced programmer removes fax : (206) 543-2969 defective code." -- ------------------------------------------------------------------------------ Richard E. Pattis "Programming languages are like Department of Computer Science pizzas - they come in only "too" and Engineering sizes: too big and too small."