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-Thread: 103376,910a48a538936849 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: how to import a package References: <1165371252.358817.57840@80g2000cwy.googlegroups.com> In-Reply-To: <1165371252.358817.57840@80g2000cwy.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1165434458 12.201.97.213 (Wed, 06 Dec 2006 19:47:38 GMT) NNTP-Posting-Date: Wed, 06 Dec 2006 19:47:38 GMT Date: Wed, 06 Dec 2006 19:47:38 GMT Xref: g2news2.google.com comp.lang.ada:7826 Date: 2006-12-06T19:47:38+00:00 List-Id: markww wrote: > Hi, > > I have this snippet of code (from members here) which defines a generic > type: > > generic > type T is private; > package P is > type Node; > type Node_Ptr is access Node; > type Node is record > Data : T; > Prev_Rec : access Node; -- points to the next record or > null if none exists. > Next_Rec : access Node; -- points to the previous record or > null if none exists. > end record; > end P; > > Now my compiler (gnat) complains that Node, and Node_Ptr are not seen > by the rest of the application. Is this because they are scoped within > package P? Package are very basic to Ada. 1st you must know how to make use of a package. If you don't know that, you're not ready to do anything useful with Ada. In general, if you have a library-level package P, you make it visible to another compilation unit through a context clause: with P; package Q is ... In this case, you have a generic package, which is not a package but a way to create a package tailored to your needs. You can only mention a generic package in a context clause or instantiation. You still have to mention it in a context clause: with P; procedure My_Project is then you have to use it to make a new package (instantiation): package X is new P (T => Person_Rec); Now the things declared in P are available in X. You have to use a qualified name to access them: X. Node. (Since you're a beginner, I'd recommend avoiding the use clause until you have a better idea how these things work.) The above is for the most common case that P is a library-level generic package. In your case it appears your generic package is declared in your main procedure (which is not very useful), so it is not library-level and is directly visible; you neither need nor can use a context clause for P. But all this is very basic. You should work through a tutorial or text and understand packages and generic packages before trying this; both are available at adapower.com or adaworld.com. It would also help if you used basic Ada indentation standards: generic type T is private; package P is type Node; ... end P; Again, by the time you've worked through a tutorial or text you should have been exposed to a bunch of examples, and will hopefully have seen the logic behind the common indentation approach. If you've already been through a tutorial or text, including generics, then there's something you didn't understand. In that case, I'm not sure which part you didn't understand. -- Jeff Carter "People called Romanes, they go the house?" Monty Python's Life of Brian 79