From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,131f3be06911dc7e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-03 01:27:44 PST Path: archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-atanamir.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Generic Package Date: Wed, 03 Dec 2003 10:31:38 +0100 Message-ID: References: NNTP-Posting-Host: tar-atanamir.cbb-automation.de (212.79.194.116) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1070443662 70733356 212.79.194.116 ([77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:3089 Date: 2003-12-03T10:31:38+01:00 List-Id: On 2 Dec 2003 15:15:45 -0800, ratsonjaniv@hotmail.com (Mr. J.) wrote: >Hi, >I have this code : > >********************************************************************* >generic > type Language is array (Positive range<>) of Character; > type States is array (Positive range <>) of Integer; > > package Automat_Producer is > > type StatesFunctions is array(Character,Integer) of Integer; > > procedure Init(Q0:Integer); > procedure Change_State(C:Character); > function Is_Final_State return Boolean; > >private > > Statesarr: Statesfunctions; > Currentstate : Integer; > FinalStates : States; > >end Automat_Producer; >********************************************************************* > >I have few Questions: > >How and when do I set the sizes of the generic types arrays? Upon instantiation. >The compiler need to know the size of the FinalStates:States member, I >will know it only during run-time, How do I do it? >I think I need somthing similiar to C++'s Constructor. Not necessariliy. You have to constrain the variable States. There are many ways to do what you need. For example 1. you can pass the array bounds as the parameters: generic Number_Of_Final_States : Positive; type States is array (Positive range <>) of Integer; ... -- Other generic formal parameters package Automat_Producer is ... -- Public interface private FinalStates : States (1..Number_Of_Final_States); ... -- Other private things end Automat_Producer; So you could instantiate Automat_Producer with a desired number of states: package My_Producer is new Automat_Producer (Number_Of_Final_States => 10, ...); 2. you can pass the set of final states as a parameter: generic type States is array (Positive range <>) of Integer; FinalStates : States; ... -- Other generic formal parameters package Automat_Producer is ... -- Public interface private -- Do not need a list of final states it is a parameter now ... -- Other private things end Automat_Producer; 3. you could make the states an enumeration type with a domain set separated into final and non-final states: generic type State is (<>); First_Final_State : State; Last_Final_State : State; ... -- Other generic formal parameters package Automat_Producer is ... -- Public interface private -- Do not need a list of final states, a state is tested -- as if X in First_Final_State..Last_Final_State then -- ... -- Other private things end Automat_Producer; 4. you could provide a tester: generic type State is (<>); with function Is_Final (This : State) return Boolean; ... -- Other generic formal parameters package Automat_Producer is ... -- Public interface private -- Do not need a list of final states, a state is tested -- using Is_Final. ... -- Other private things end Automat_Producer; -- Regards, Dmitry Kazakov http://www.dmitry-kazakov.de