comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Generic Packages in Ada
Date: 2000/08/10
Date: 2000-08-10T00:00:00+00:00	[thread overview]
Message-ID: <v5vk5.33880$0W4.917686@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: 39926569@newsserver1.picknowl.com.au

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 <atm@picknowl.com.au> 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)
>
>
>





  reply	other threads:[~2000-08-10  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-10  0:00 Generic Packages in Ada Ashley Manos
2000-08-10  0:00 ` David C. Hoos, Sr. [this message]
2000-08-10  0:00 ` Samuel T. Harris
2000-08-11  0:00   ` Martin Dowie
2000-08-14  0:00     ` Samuel T. Harris
2000-08-14  0:00       ` Ada 83 Booch [was Generic Packages in Ada] Vincent Marciante
2000-08-10  0:00 ` Generic Packages in Ada JMS
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox