[comp.lang.misc] HELP needed!!

klaiber@udel.EDU (Alexander Klaiber) (07/08/87)

HELP!!!!!
I am doing a high-level comparison of high-level languages and I've run
into a severe problem with Ada. What I am trying to do is the following:

Assume I have a generic package linked_list that, given some type "item",
defines a type "list" which is a list of "item".

I want to write a package that defined two types, A and B and operations on
these. Now my problem is that both A and B are records and A includes a
field of type "list of B" and B includes a field of type "list of A". I
want the lists to be handled by the generic linked_list. However, the
following obviously doesn't work:

	 package my_package is

	    type A is private;
	    type B is private;

	    package list_of_A is new linked_list(A);	-- ** problem **
	    package list_of_B is new linked_list(B);	-- ** problem **

	    -- operations on A/B and "list of A"/B go here

	 private
	    type A is record
		     xxx : list_of_A.list;
		  end record;
	    type B is record
		     xxx : list_of_B.list;
		  end record;
	 end my_package;

My compiler complains about A/B not being fully defined in the generic
instantiation of linked_list. As Ada doesn't seem to support cyclic import,
I see no way of splitting up this package.

Note that I always can define the "list of A/B" explicitly by using 
	type A is record
		  xxx : ptr_to_B_node;
	       end;
	(other type declarations here)

and writing procedures to handle the lists. However, this would (a) prevent
me from using the already existing generic package and (b) I would have to
include two copies of list-handlers, one for "lists of A" and one for
"lists of B". This would make Ada look unnecessarily bad. 

Any ideas how to work around this problem?

P.S. I haven't been programming in Ada all too long, so I may be
     overlooking the obvious...


Alexander Klaiber
klaiber@dewey.udel.edu