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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107e1d,c8f58d04ea55331 X-Google-Attributes: gid107e1d,public X-Google-Thread: 103376,c8f58d04ea55331 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Generic Packages in Ada Date: 2000/08/10 Message-ID: #1/1 X-Deja-AN: 656695979 Content-Transfer-Encoding: 7bit References: <39926569@newsserver1.picknowl.com.au> Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 965901787 63.178.180.1 (Thu, 10 Aug 2000 03:03:07 PDT) Organization: Ada95 Press, Inc. MIME-Version: 1.0 NNTP-Posting-Date: Thu, 10 Aug 2000 03:03:07 PDT Newsgroups: comp.lang.ada,fr.comp.lang.ada Date: 2000-08-10T00:00:00+00:00 List-Id: The problem the compiler has is that it has no way of knowing that every actual type Node with which the generic may be instantiated is in fact a record with a component named Next. You are trying to _import_ into your generic package information about how a list is implemented. Instead, this information should be hidden within the generic package. In other words, if you only have the generic formal parameter Item (for example), which is the type of a list element, and then export the List type from the generic package, you can then declare in the generic package the structure of your (generic) list. The pointer to the next element is _not_ a component of a list element, but, rather, a generic node contains two components -- a list element, and a pointer to the next _node_. Ashley Manos wrote in message news:39926569@newsserver1.picknowl.com.au... > Hi - can anyone help me with this: > > I'm attempting to write a generic package for linked lists in Ada. > The data structure I'm looking to make generic is the element > ie each element in the list is composed of 2 parts: the elemtn and a pointer > to the next element. > > So my package spec looks something like this: > > generic > type Node is private; -- here's the list element > type List is access Node; -- here's the pointer to the next element > in the list > > package Lists is > function CreateList(N:in Node) return List; > procedure AddToRear(N:in Node; L:in out List); > procedure RemoveFirst(N:in Node; L:in out List); > end Lists; > > However, the compiler is complaining (and rightly so!) about my package > body, the start of which looks like this: > > package body Lists is > > function CreateList(N:in Node) return List is > L:List; > begin > L:= new Node; > L.Next:= Null; *** > return L; > end CreateList; > > ............... etc .................. > > The compiler is saying "invalid prefix in selected component L" about the > line ***. > I can see why the compiler is raising this error, but I need my function to > refer to the "Next" component of the element, as it will be of type "List" > ie the pointer to the next element. > > If this makes absolutely any sense to anybody that might be able to help, > could you PLEASE reply. > > Thanks > Ashley (atm@picknowl.com.au) > > >