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: 6 Dec 2006 15:56:36 -0800 Organization: http://groups.google.com Message-ID: <1165449396.112251.129200@l12g2000cwl.googlegroups.com> References: <1165371252.358817.57840@80g2000cwy.googlegroups.com> NNTP-Posting-Host: 66.65.64.109 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1165449401 12408 127.0.0.1 (6 Dec 2006 23:56:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 6 Dec 2006 23:56:41 +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=66.65.64.109; posting-account=cNKOMg0AAADT2ug8oGSYYXo8bsDvrHzw Xref: g2news2.google.com comp.lang.ada:7832 Date: 2006-12-06T15:56:36-08:00 List-Id: Yes I'm still confused - sorry - I'm coming from C++ / java and the ada syntax / scoping is a bit strange to me. So I thought a package is equivalent to a structure/class. I thought that the following line: package Person_List in new P (T => PERSON_REC) is just instantiating one instance of the package called Person_List. So the line: Start : Person_List.Node_Ptr; doesn't make sense to me since it looks like 'Start' is being defined as pointing to Person_List.Node_Ptr, when I thought the right side of the colon must be a data type. In any event, I can't event get past adding the following line under the package: package Person_List is new P (T => PERSON_REC); my compiler (gnat) gives an error saying: operator for type "Node_Ptr" defined at line 23, nstance at line 39 is not directly visible use clause would make operation legal line 39 is the line I just listed above. Line 23 is where Node_Ptr is defined in the package. So ok, I stick the line: use Person_List; underneath 'package Person_List is new P (T => PERSON_REC); ' but the compiler still throws the same error. Thanks, Mark Jeffrey R. Carter wrote: > 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