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,FROM_NUMERIC_TLD 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!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!bbc!news-peer-lilac.gradwell.net!not-for-mail From: "Stuart" Newsgroups: comp.lang.ada 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> <1165893584.829025.235440@l12g2000cwl.googlegroups.com> Subject: Re: how to import a package Date: Tue, 12 Dec 2006 09:03:48 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Message-ID: <457e6d69$1_1@glkas0286.greenlnk.net> X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1165914243 news.gradwell.net 624 dnews/20.133.0.1:58375 X-Complaints-To: news-abuse@gradwell.net Xref: g2news2.google.com comp.lang.ada:7899 Date: 2006-12-12T09:03:48+00:00 List-Id: "markww" wrote in message news:1165893584.829025.235440@l12g2000cwl.googlegroups.com... > 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: > am I allowed to do the same in my package definition? Then things would > be a lot neater. As Jeff Carter explained - yes you can. The approach you currently have is often referred to as an Abstract Data Type (ADT), whereas what you are considering is an Abstract State Machine (ASM). The topic is worth researching. It is a very important program design consideration as to whether to make something an ADT or an ASM as it controls the location of state and the nature of the interface. This is a lesson that is emphasized in the design of SPARK (see www.sparkada.com) programs. Given an ADT it is quite straightforward to create an ASM; you simply create a package that contains the state variable and replicates each of the ADT operations, omitting the Object parameter from their own parameter list and using the state variable when calling the ADT operation to provide the functionality. package ADT is type T is private; procedure Add(Item : in integer; To : in out T); function Initialize(Initial : in integer) return T; private type T is integer; -- Just a demo! end ADT; with ADT; package ASM is procedure Add(Item : in integer); private State : ADT.T := ADT.Initialize(0); end ASM; package body ASM is procedure Add(Item : in integer) is begin ADT.Add(Item => Item, To => State); end Add; end ASM; > 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: Why do you have them as separate variables? You could create a type (call it, say, List) that has both these components. Having 'cracked' generics you might want to go back and think very carefully about what the 'visible' parts of your ADT/ASM are, and what are 'private' details. Generally the more you make private the less chance there is of things getting messed up, and the easier it is to make changes to the underlying type to develop/extend/improve your design. Jeff's suggestion of looking at the design of packages like Containers is a good one. Regards -- Stuart