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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,910a48a538936849 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!l12g2000cwl.googlegroups.com!not-for-mail From: "markww" Newsgroups: comp.lang.ada Subject: Re: how to import a package Date: 11 Dec 2006 19:19:44 -0800 Organization: http://groups.google.com Message-ID: <1165893584.829025.235440@l12g2000cwl.googlegroups.com> References: <1165371252.358817.57840@80g2000cwy.googlegroups.com> <4577dc92$1_1@glkas0286.greenlnk.net> <7ft8le.vk1.ln@hunter.axlog.fr> <1165817760.736164.218530@73g2000cwn.googlegroups.com> <1165819804.449958.305980@73g2000cwn.googlegroups.com> <1165830005.15844.5.camel@localhost> <1165846777.475130.199390@f1g2000cwa.googlegroups.com> NNTP-Posting-Host: 68.174.181.181 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1165893590 6816 127.0.0.1 (12 Dec 2006 03:19:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 12 Dec 2006 03:19:50 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: l12g2000cwl.googlegroups.com; posting-host=68.174.181.181; posting-account=cNKOMg0AAADT2ug8oGSYYXo8bsDvrHzw Xref: g2news2.google.com comp.lang.ada:7897 Date: 2006-12-11T19:19:44-08:00 List-Id: Thanks all I think I got it now. Dmitry A. Kazakov, Adam Beneschan, your posts really showed me how to set it up. Now I have all the list functions as part of that package and it's working as expected for a generic list. I'm wondering still if it's possible to have a data member in the package definition that serve as my start and end nodes. In C++ I'd do something like: struct List { AddNode(...); DeleteNode(...); ... Node *pStart, *pEnd; // keeps track of start and end nodes for a single list instance. } am I allowed to do the same in my package definition? Then things would be a lot neater. Right now I have the start and end pointers as variables external to the package, so everytime I call AddNode() etc I have to pass them through which is pretty sloppy. It looks like: generic type T is private; package Generic_List is type Node; type Node_Ptr is access Node; type Node is limited record -- We don't copy nodes Data : T; -- The data in the node Prev : Node_Ptr; -- Previous node, else null Next : Node_Ptr; -- Next node, else null end record; procedure Add(Start : in out Node_Ptr; Last : in out Node_Ptr; Data : T); procedure Delete(Start : in out Node_Ptr; Last : in out Node_Ptr; nIndex : INTEGER); function GetNodeCount (Start : Node_Ptr) return INTEGER; function GetNode(Start : Node_Ptr; nIndex : INTEGER) return Node_Ptr; function GetNodePosition(Start : Node_Ptr; MatchData : T) return INTEGER; -- Something like: m_Start : Node_Ptr; m_Last : Node_Ptr; end Generic_List; then externally I'd hope to use it like: GenericList.Add(T); instead of what I'm doing now: GenericList.Add(Start, Last, T); Thanks, Mark Jeffrey R. Carter wrote: > markww wrote: > > > > procedure Add_Record(GenericData : PERSON_REC) is > > Temp : gNode.Node_Ptr; > > begin > > > > Temp := new gNode.Node; > > Temp.Data := GenericData; > > end Add_Record; > > This leaks memory. > > Others have discussed the solution to your specific problem, but I think > what you're missing is the general mind-set that a type definition and > the operations on that type should be encapsulated in a package. So far, > you only have 1 operation (Add_Record), but in a generally useful > linked-list package you'd probably have a lot more. Those operations > should be in the package; then, whenever you instantiate the package, > you get the operations. > > This concept, encapsulation of data and their operations (usually with > hiding of the data's structure), is called "object orientedness". In > many languages, this design concept is mixed up with the implementation > concept of programming by extension (incorrectly called OOP); for > example, in C++, you get both from the "class" construct. In Ada, the 2 > are separate. > > At this point, you might find it instructive to look at some existing > linked-list packages, such as the one in the Ada-0X container library, > or the ones in the PragmAda Reusable Components > > http://pragmada.home.mchsi.com/ > > or many of the component libraries you can find at adapower.com or > adaworld.com. > > -- > Jeff Carter > "Blessed is just about anyone with a vested interest in the status quo." > Monty Python's Life of Brian > 73