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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,407c890f49bff7e2,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-23 23:15:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn1feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail From: Caffeine Junky Subject: A little help on Generics. Newsgroups: comp.lang.ada User-Agent: Pan/0.11.3 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: ALL Message-ID: NNTP-Posting-Host: 12.245.48.122 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1024899342 12.245.48.122 (Mon, 24 Jun 2002 06:15:42 GMT) NNTP-Posting-Date: Mon, 24 Jun 2002 06:15:42 GMT Organization: AT&T Broadband Date: Mon, 24 Jun 2002 06:15:42 GMT Xref: archiver1.google.com comp.lang.ada:26637 Date: 2002-06-24T06:15:42+00:00 List-Id: So far I've got Accesses and arrays and stuff figured out. I've kinda got the package system figured out. But I'm having trouble figuring out how to use Generics. More specifically, I know how to create a generic package(at least the compiler doesnt give me any errors when making an object file). I just dont know the proper way to instantiate it. Heres a package spec and a test file that you guys can peak at and hopefully give me some hints as to what I'm doing wrong. (Please be kind, I'm still a newbie. Heh.) generic Max : Positive; type Item is private; package genstack is -- I created this package so that I could practice using -- -- Generics. -- -- Nothing fancy here. -- type Stack is limited private; procedure Push(X : in Item; S : in out Stack); function Pop(S: in Stack) return Item; function Is_Empty(S : in Stack) return Boolean; private type Cell; type Stack is access Cell; type Cell is record Value: Item; Next: Stack; end record; -- This package will be expanded to include other kinds of stacks -- -- as time permits. -- end genstack; That's the specification. Everything looks good to my untrained eye. How about yours? And this is the test/practice code I'm using... with Text_IO; with genstack; procedure test is Alphs : constant String := "ABCDEFGHIJKLMNOP"; Ints : array(Integer range 0..500) of Integer; begin declare type Int_Stack is new genstack(Max => 500, Item => Integer); use Int_Stack; Ret: Integer; Some_Ints: Stack; begin -- Initialize the Integer array here. -- for Z in Ints'Range loop Ints(Z) := Z; end loop; for J in Ints'Range loop Text_IO.Put_Line("Pushing number"& Ints(J)'Img &"onto the stack"); Push(Ints(J), Some_Ints); end loop; Text_IO.Put_Line("Finished Pushing all numbers onto the stack."); Text_IO.New_Line; for D in Ints'Range loop Ret := Pop(Some_Ints); Text_IO.Put_Line("Popped"& Ret'Img &" from the stack."); end loop; end; declare type Alph_Stack is new genstack(Max => 16, Item => Character); Letters : String(1..16); use Alph_Stack; A_Word : Alph_Stack; begin Text_IO.Put_Line("Pushing Letters onto the stack."); for Y in Alphs'Range loop Push(Alph(Y), A_Word); end loop; Text_IO.Put_Line("Finished Pushing letters onto the stack."); Text_IO.New_Line; Text_IO.Put_Line("Now Popping the letters from the stack"); for N in Alphs'Range loop Letters(N) := Pop(A_Word); Text_IO.Put_Line("Popped letter"& Letters(N) &"from the Stack"); end loop; end; end test; Any help would be appreciated. Thanks St4pL3