comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <samuel_t_harris@Raytheon.com>
Subject: Re: Generic Packages in Ada
Date: 2000/08/10
Date: 2000-08-10T00:00:00+00:00	[thread overview]
Message-ID: <3992B839.6918FE77@Raytheon.com> (raw)
In-Reply-To: 39926569@newsserver1.picknowl.com.au

Ashley Manos wrote:
> 
> 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

Here you declare a generic formal type which is an access to
a generic private type. You generic package has no knowledge
of the structure of the Node type!

> 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;

As a side note, I personally abhore mixed-case squishing-words-together
style of code. Just what is wrong with Create_List, Add_to_Rear,
and Remove_First. Are underscores such a problem. Add to the fact
that most code pretty-printers will drop the succeeding upper case
letter to lowe case and you will actually get Createlist, Addtorear,
and Removefirst. I find this to be completely unreadable!

> 
> 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;    ***

Since L.all is of type Node, a generic formal private type,
your code here has absolutely no knowledge of anything about
type Node. Node could be an integer type, an array, a fixed
point type, anything! There is nothing to imply to the generic
that L points to a record of which Next is some component!

>         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.

I suggest you get a copy of Grady Booch's tome on software components
in Ada. He discusses in great detail the reasoning behind his
design choices and provides extensive discussion on List packages.

> 
> Thanks
> Ashley (atm@picknowl.com.au)

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"




  parent 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.
2000-08-10  0:00 ` Samuel T. Harris [this message]
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