From: terminus.umd.edu!brad@umd5.umd.edu (Brad Balfour)
Subject: Re: Help with Exceptions for Generic Instantiation
Date: 16 Dec 91 14:28:02 GMT [thread overview]
Message-ID: <brad.692893682@terminus.umd.edu> (raw)
ae@sei.cmu.edu (Arthur Evans) replies:
>pattis@cs.washington.edu (Richard Pattis) asks about parameterizing a
>generic with an exception.
>Well, if you are missing something it's because it isn't there. Ada 83
>has no mechanism to do what you want. Ada 9X will, but that doesn't
>help much right now.
>Art Evans
Well... Not necessarily.
Draft 3.1 of the Ada 9X Mapping Specification from August 1991 does not
have exceptions as generic formal parameters. And, (IMHO) it doesn't look likel
y
that this will change unless people demand it.
However, the Mapping/Revision Team has proposed another mechanism that might
work in this case: Generic formal package parameters.
I have attempted to work out Rich's example with the new (as of v3.1) syntax.
-- new --
Generic -- must be generic to be passed as a generic formal parameter
-- rest is same as before --
PACKAGE File_Stream IS
...
END File_Stream;
A simple echo utility might then be written as follows (modified for 9X v3.1):
WITH Terminal_Utility, String_Utility; -- His own I/O interfaces
GENERIC
Message : IN STRING;
with package A_Stream is new File_Stream(<>) ;
-- any instantiation of File_Stream will match this parameter
PROCEDURE Echo;
PROCEDURE Echo IS
PACKAGE SU RENAMES String_Utility;
PACKAGE TTY RENAMES Terminal_Utility;
S : A_Stream.Stream;
C : CHARACTER;
BEGIN
Open(S, TTY.Prompt(Message));
BEGIN
LOOP
A_Stream.Get(C, S);
TTY.Announce(C);
END LOOP;
EXCEPTION
WHEN A_Stream.No_More_Data_Error => -- now the exception name is visible
Close(S);
END;
TTY.Announce(SU.CR);
END Echo;
Hope this helps.
------
Brad Balfour
EVB Software Engineering, Inc.
1-800-877-1815
brad@terminus.umd.edu
next reply other threads:[~1991-12-16 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-12-16 14:28 Brad Balfour [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-12-16 21:17 Help with Exceptions for Generic Instantiation Brad Balfour
1991-12-13 20:10 Arthur Evans
1991-12-13 17:27 Richard Pattis
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox