* Generic Packages in Ada
@ 2000-08-10 0:00 Ashley Manos
2000-08-10 0:00 ` JMS
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Ashley Manos @ 2000-08-10 0:00 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generic Packages in Ada
2000-08-10 0:00 Generic Packages in Ada Ashley Manos
2000-08-10 0:00 ` JMS
@ 2000-08-10 0:00 ` David C. Hoos, Sr.
2000-08-10 0:00 ` Samuel T. Harris
2 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2000-08-10 0:00 UTC (permalink / raw)
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)
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generic Packages in Ada
2000-08-10 0:00 Generic Packages in Ada Ashley Manos
2000-08-10 0:00 ` JMS
2000-08-10 0:00 ` David C. Hoos, Sr.
@ 2000-08-10 0:00 ` Samuel T. Harris
2000-08-11 0:00 ` Martin Dowie
2 siblings, 1 reply; 7+ messages in thread
From: Samuel T. Harris @ 2000-08-10 0:00 UTC (permalink / raw)
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!"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generic Packages in Ada
2000-08-10 0:00 Generic Packages in Ada Ashley Manos
@ 2000-08-10 0:00 ` JMS
2000-08-10 0:00 ` David C. Hoos, Sr.
2000-08-10 0:00 ` Samuel T. Harris
2 siblings, 0 replies; 7+ messages in thread
From: JMS @ 2000-08-10 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 19554 bytes --]
Hi
Here is what I wrote which worked with Aonix compiler (I am sorry I am
french as you willl note...). If you need any translation help don't
hesitate asking me.:
with unchecked_deallocation;
generic
type Contenu is private;
package Pile is
type Element is limited private;
type AccesElement is access Element;
pileAlteree: exception;
pileVide: exception;
indexNul: exception;
indexTropGrand: exception;
indexHorsPile: exception;
procedure AjouterElementEnDebut( enregistrement: in Contenu);
procedure EnleverElementEnDebut( enregistrement: out Contenu);
procedure AjouterElementEnFin( enregistrement: in Contenu);
procedure EnleverElementEnFin( enregistrement: out Contenu);
procedure ExtraireElement( enregistrement: out Contenu;
index: in Integer);
procedure SupprimerElement( index: in Integer);
procedure InsererAvantElement( enregistrement: in Contenu;
indexDeReference: in Integer);
procedure InsererApresElement( enregistrement: in Contenu;
indexDeReference: in Integer);
function NombreDElements return Integer;
function ContenuElement(index: integer) return Contenu;
private
type Element is
record
predecesseur: AccesElement:= null;
successeur: AccesElement:= null;
contenuElement: Contenu;
index: Integer:= 0;
end record;
pointeurPremierElement: AccesElement:= null;
pointeurDernierElement: AccesElement:= null;
end Pile;
with Espionnage;
package body Pile is
procedure AjouterElementEnDebut( enregistrement: in Contenu) is
pointeur: AccesElement:= null;
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("AjouterElementEnDebut");
end if;
pointeur:= new Element'(null,null,enregistrement,0);
if pointeurPremierElement = null then
if pointeurDernierElement = null then
pointeurPremierElement:= pointeur;
pointeurDernierElement:= pointeur;
pointeur.index:= 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeur.index,"Index initial: ");
end if;
else
Espionnage.Commenter("Pile alteree: pas de premier element mais un
dernier element existe!");
raise pileAlteree;
end if;
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
begin
pointeurPremierElement:= pointeur;
pointeur.index:= 1;
pointeur.successeur:= pointeurCourant;
pointeur.successeur.predecesseur:= pointeur;
while pointeurCourant /= null loop
pointeurCourant.index:= pointeurCourant.index + 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourant.index,"Mise � jour des
index: ");
end if;
pointeurCourant:= pointeurCourant.successeur;
end loop;
end;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("AjouterElementEnDebut");
end if;
end AjouterElementEnDebut;
procedure EnleverElementEnDebut(enregistrement: out Contenu) is
pointeur: AccesElement:= null;
procedure Liberer is new unchecked_deallocation(Element,AccesElement);
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("EnleverElementEnDebut");
end if;
if pointeurPremierElement = null then
if pointeurDernierElement = null then
Espionnage.Commenter("Pile vide!");
raise pileVide;
else
Espionnage.Commenter("Pile alteree: pas de premier element mais un
dernier element existe!");
raise pileAlteree;
end if;
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
begin
pointeur:= pointeurCourant;
pointeurCourant:= pointeurCourant.successeur;
pointeurPremierElement:= pointeurCourant;
enregistrement:= pointeur.contenuElement;
pointeur.successeur:= null;
pointeur.predecesseur:= null;
pointeur.index:= 0;
if pointeurCourant /= null then
pointeurCourant.predecesseur:= null;
end if;
while pointeurCourant /= null loop
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourant.index,"Index initial: ");
end if;
pointeurCourant.index:= pointeurCourant.index - 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourant.index,"Index final: ");
end if;
pointeurCourant:= pointeurCourant.successeur;
end loop;
if pointeur = pointeurDernierElement then
pointeurDernierElement:= null;
end if;
Liberer(pointeur);
end;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("EnleverElementEnDebut");
end if;
end EnleverElementEnDebut;
procedure AjouterElementEnFin( enregistrement: in Contenu) is
pointeur: AccesElement:= null;
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("AjouterElementEnFin");
end if;
pointeur:= new Element'(null,null,enregistrement,0);
if pointeurDernierElement = null then
if pointeurPremierElement = null then
pointeurPremierElement:= pointeur;
pointeurDernierElement:= pointeur;
pointeur.index:= 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeur.index,"Index final: ");
end if;
else
Espionnage.Commenter("Pile alteree: pas de dernier element mais un
premier element existe!");
raise pileAlteree;
end if;
else
declare
pointeurCourant: AccesElement:= pointeurDernierElement;
begin
pointeurDernierElement:= pointeur;
pointeur.index:= pointeurCourant.index + 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeur.index,"Index final: ");
end if;
pointeur.predecesseur:= pointeurCourant;
pointeur.predecesseur.successeur:= pointeur;
end;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("AjouterElementEnFin");
end if;
end AjouterElementEnFin;
procedure EnleverElementEnFin(enregistrement: out Contenu) is
pointeur: AccesElement:= null;
procedure Liberer is new unchecked_deallocation(Element,AccesElement);
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("EnleverElementEnFin");
end if;
if pointeurDernierElement = null then
if pointeurPremierElement = null then
Espionnage.Commenter("Pile vide!");
raise pileVide;
else
Espionnage.Commenter("Pile alteree: pas de dernier element mais un
premier element existe!");
raise pileAlteree;
end if;
else
declare
pointeurCourant: AccesElement:= pointeurDernierElement;
begin
pointeur:= pointeurCourant;
pointeurCourant:= pointeurCourant.predecesseur;
pointeurDernierElement:= pointeurCourant;
enregistrement:= pointeur.contenuElement;
pointeur.successeur:= null;
pointeur.predecesseur:= null;
pointeur.index:= 0;
if pointeurCourant /= null then
pointeurCourant.successeur:= null;
end if;
if pointeur = pointeurPremierElement then
pointeurPremierElement:= null;
end if;
Liberer(pointeur);
end;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("EnleverElementEnFin");
end if;
end EnleverElementEnFin;
procedure ExtraireElement( enregistrement: out Contenu;
index: in Integer) is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("ExtraireElement");
end if;
if index = 0 then
Espionnage.Commenter("Extraction impossible, index de l'element a extraire
nul!");
raise indexNul;
else
if index > pointeurDernierElement.index then
Espionnage.Commenter("Extraction impossible, index de l'element a
extraire trop grand!");
raise indexTropGrand;
else
if index = 1 then
EnleverElementEnDebut(enregistrement);
else
if index = pointeurDernierElement.index then
EnleverElementEnfin(enregistrement);
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
indexTrouve: Boolean:= false;
procedure Liberer is new unchecked_deallocation(Element,AccesElement);
begin
while pointeurCourant /= null loop
if index = pointeurCourant.index then
indexTrouve:= true;
enregistrement:= pointeurCourant.contenuElement;
pointeurCourant.index:= 0;
pointeurCourant.predecesseur.successeur:=
pointeurCourant.successeur;
pointeurCourant.successeur.predecesseur:=
pointeurCourant.predecesseur;
declare
pointeurCourantInterne: AccesElement:= pointeurCourant.successeur;
begin
while pointeurCourantInterne /= null loop
pointeurCourantInterne.index:= pointeurCourantInterne.index - 1;
pointeurCourantInterne:= pointeurCourantInterne.successeur;
end loop;
end;
pointeurCourant.predecesseur:= null;
pointeurCourant.successeur:= null;
Liberer(pointeurCourant);
exit;
end if;
pointeurCourant:= pointeurCourant.successeur;
end loop;
if not(indexTrouve) then
raise indexHorsPile;
end if;
end;
end if;
end if;
end if;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("ExtraireElement");
end if;
end ExtraireElement;
procedure SupprimerElement(index: in Integer) is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("SupprimerElement");
end if;
if index = 0 then
Espionnage.Commenter("Suppression impossible, index de l'element a
supprimer nul!");
raise indexNul;
else
if index > pointeurDernierElement.index then
Espionnage.Commenter("Suppression impossible, index de l'element a
supprimer trop grand!");
raise indexTropGrand;
else
if index = 1 then
declare
enregistrement: Contenu;
begin
EnleverElementEnDebut(enregistrement);
end;
else
if index = pointeurDernierElement.index then
declare
enregistrement: Contenu;
begin
EnleverElementEnfin(enregistrement);
end;
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
indexTrouve: Boolean:= false;
procedure Liberer is new unchecked_deallocation(Element,AccesElement);
begin
while pointeurCourant /= null loop
if index = pointeurCourant.index then
indexTrouve:= true;
pointeurCourant.index:= 0;
pointeurCourant.predecesseur.successeur:=
pointeurCourant.successeur;
pointeurCourant.successeur.predecesseur:=
pointeurCourant.predecesseur;
declare
pointeurCourantInterne: AccesElement:= pointeurCourant.successeur;
begin
while pointeurCourantInterne /= null loop
pointeurCourantInterne.index:= pointeurCourantInterne.index - 1;
pointeurCourantInterne:= pointeurCourantInterne.successeur;
end loop;
end;
pointeurCourant.predecesseur:= null;
pointeurCourant.successeur:= null;
Liberer(pointeurCourant);
exit;
end if;
pointeurCourant:= pointeurCourant.successeur;
end loop;
if not(indexTrouve) then
raise indexHorsPile;
end if;
end;
end if;
end if;
end if;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("SupprimerElement");
end if;
end SupprimerElement;
procedure InsererAvantElement( enregistrement: in Contenu;
indexDeReference: in Integer) is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("InsererAvantElement");
end if;
if indexDeReference = 0 then
Espionnage.Commenter("Insertion impossible, index de l'element de
reference nul!");
raise indexNul;
else
if indexDeReference > pointeurDernierElement.index then
Espionnage.Commenter("Insertion impossible, index de l'element de
reference trop grand!");
raise indexTropGrand;
else
if indexDeReference = 1 then
AjouterElementEnDebut(enregistrement);
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
indexTrouve: Boolean:= false;
begin
while pointeurCourant /= null loop
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourant.index,"Index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
if pointeurCourant.index = indexDeReference then
declare
pointeur: AccesElement:= null;
pointeurCourantInterne: AccesElement:= pointeurCourant;
begin
indexTrouve:= true;
pointeur:= new
Element'(pointeurCourant.predecesseur,pointeurCourant,enregistrement,indexDe
Reference);
pointeurCourant.predecesseur.successeur:= pointeur;
pointeurCourant.predecesseur:= pointeur;
while pointeurCourantInterne /= null loop
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourantInterne.index,"Ancien
index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
pointeurCourantInterne.index:= pointeurCourantInterne.index + 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourantInterne.index,"Nouvel
index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
pointeurCourantInterne:= pointeurCourantInterne.successeur;
end loop;
exit;
end;
else
pointeurCourant:= pointeurCourant.successeur;
end if;
end loop;
if not(indexTrouve) then
raise indexHorsPile;
end if;
end;
end if;
end if;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("InsererAvantElement");
end if;
end InsererAvantElement;
procedure InsererApresElement( enregistrement: in Contenu;
indexDeReference: in Integer) is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("InsererApresElement");
end if;
if indexDeReference = 0 then
Espionnage.Commenter("Insertion impossible, index de l'element de
reference nul!");
raise indexNul;
else
if indexDeReference > pointeurDernierElement.index then
Espionnage.Commenter("Insertion impossible, index de l'element de
reference trop grand!");
raise indexTropGrand;
else
if indexDeReference = pointeurDernierElement.index then
AjouterElementEnFin(enregistrement);
else
declare
pointeurCourant: AccesElement:= pointeurDernierElement;
indexTrouve: Boolean:= false;
begin
while pointeurCourant /= null loop
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourant.index,"Index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
if pointeurCourant.index = indexDeReference then
declare
pointeur: AccesElement:= null;
pointeurCourantInterne: AccesElement:= null;
begin
indexTrouve:= true;
pointeur:= new
Element'(pointeurCourant,pointeurCourant.successeur,enregistrement,indexDeRe
ference +1);
pointeurCourant.successeur.predecesseur:= pointeur;
pointeurCourant.successeur:= pointeur;
pointeurCourantInterne:= pointeur.successeur;
while pointeurCourantInterne /= null loop
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourantInterne.index,"Ancien
index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
pointeurCourantInterne.index:= pointeurCourantInterne.index + 1;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurCourantInterne.index,"Nouvel
index courant: ");
Espionnage.EspionnerEntier(indexDeReference,"Reference: ");
end if;
pointeurCourantInterne:= pointeurCourantInterne.successeur;
end loop;
exit;
end;
else
pointeurCourant:= pointeurCourant.predecesseur;
end if;
end loop;
if not(indexTrouve) then
raise indexHorsPile;
end if;
end;
end if;
end if;
end if;
if Espionnage.espionnage then
Espionnage.MarquerSortie("InsererApresElement");
end if;
end InsererApresElement;
function NombreDElements return Integer is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("NombreDElements");
end if;
if pointeurDernierElement /= null then
if Espionnage.espionnage then
Espionnage.EspionnerEntier(pointeurDernierElement.index,"Nombre : ");
Espionnage.MarquerSortie("NombreDElements");
end if;
return pointeurDernierElement.index;
else
if Espionnage.espionnage then
Espionnage.Commenter("Nombre : 0");
Espionnage.MarquerSortie("NombreDElements");
end if;
return 0;
end if;
end NombreDElements;
function ContenuElement(index: Integer) return Contenu is
begin
if Espionnage.espionnage then
Espionnage.MarquerEntree("ContenuElement");
end if;
if(index = 0) then
Espionnage.Commenter("Recherche de contenu impossible, index de l'element
a lire nul!");
raise indexNul;
else
if(index > pointeurDernierElement.index) then
Espionnage.Commenter("Recherche de contenu impossible, index de l'element
a lire trop grand!");
raise indexTropGrand;
else
if index = 1 then
if Espionnage.espionnage then
Espionnage.EspionnerEntier(index,"Index : ");
Espionnage.MarquerSortie("ContenuElement");
end if;
return pointeurPremierElement.contenuElement;
else
if index = pointeurDernierElement.index then
if Espionnage.espionnage then
Espionnage.EspionnerEntier(index,"Index : ");
Espionnage.MarquerSortie("ContenuElement");
end if;
return pointeurDernierElement.contenuElement;
else
declare
pointeurCourant: AccesElement:= pointeurPremierElement;
indexTrouve: Boolean:= false;
begin
while pointeurCourant /= null loop
if index = pointeurCourant.index then
indexTrouve:= true;
if Espionnage.espionnage then
Espionnage.EspionnerEntier(index,"Index : ");
Espionnage.MarquerSortie("ContenuElement");
end if;
return pointeurCourant.contenuElement;
end if;
pointeurCourant:= pointeurCourant.successeur;
end loop;
if not(indexTrouve) then
raise indexHorsPile;
end if;
end;
end if;
end if;
end if;
end if;
end ContenuElement;
end Pile;
@+
JMS
--
http://perso.wanadoo.fr/muriel.servais/muriel.servais/
Ashley Manos <atm@picknowl.com.au> a �crit dans le message :
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)
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generic Packages in Ada
2000-08-10 0:00 ` Samuel T. Harris
@ 2000-08-11 0:00 ` Martin Dowie
2000-08-14 0:00 ` Samuel T. Harris
0 siblings, 1 reply; 7+ messages in thread
From: Martin Dowie @ 2000-08-11 0:00 UTC (permalink / raw)
you can find the source for booch components via:
http://www.adapower.com/booch/index.html
p.s. I have found www.adapower.com to be a mine of useful stuff!
Samuel T. Harris wrote:
>
[snip]
>
> 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.
>
> --
> Samuel T. Harris, Principal Engineer
> Raytheon, Aerospace Engineering Services
> "If you can make it, We can fake it!"
--
The views expressed here are personal and not those of BAE Systems.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generic Packages in Ada
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
0 siblings, 1 reply; 7+ messages in thread
From: Samuel T. Harris @ 2000-08-14 0:00 UTC (permalink / raw)
Martin Dowie wrote:
>
> you can find the source for booch components via:
>
> http://www.adapower.com/booch/index.html
>
> p.s. I have found www.adapower.com to be a mine of useful stuff!
I was refering to the original Booch components in Ada 83.
Not the Ada 95 stuff. Besides, the book contains the discussion,
not the code. My apologies for any confusion.
There are some efforts underway to get the Booch Ada 83
components available on-line.
>
> Samuel T. Harris wrote:
> >
> [snip]
> >
> > 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.
> >
--
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Ada 83 Booch [was Generic Packages in Ada]
2000-08-14 0:00 ` Samuel T. Harris
@ 2000-08-14 0:00 ` Vincent Marciante
0 siblings, 0 replies; 7+ messages in thread
From: Vincent Marciante @ 2000-08-14 0:00 UTC (permalink / raw)
Samuel T. Harris wrote:
>
> There are some efforts underway to get the Booch Ada 83
> components available on-line.
That is correct.
However, even thought Mr. Booch, in his last email to me,
asked for the address of an FTP site at which he could drop
off the sources, that has been well over a month ago. :(
He has been swamped with work/travel since our first
correspondence wrt the components and I am assuming that
that is the current reason for the delay.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2000-08-14 0:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-10 0:00 Generic Packages in Ada Ashley Manos
2000-08-10 0:00 ` JMS
2000-08-10 0:00 ` David C. Hoos, Sr.
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox