comp.lang.ada
 help / color / mirror / Atom feed
* Readable mutually recursive data structures?
@ 1994-11-02 17:40 Michael Hagerty
  0 siblings, 0 replies; only message in thread
From: Michael Hagerty @ 1994-11-02 17:40 UTC (permalink / raw)


A straightforward question, following up on the mutually recursive
data structures thread earlier.  But for Ada-83 exclusively...

Given that I have a generic list package which is to be instantiated
using an item of user-specified type as follows:

type node_list_item_t is
  record
     In_Seg     : SegList_p := SegList_p.null_list;
     Out_Seg    : SegList_p := SegList_p.null_list;
     cost       : cost_t := (others=>0.0);
     ReqAlt     : meters := 0.0;
     Node_DB    : node_t; -- a record having meaning in this context
  end record;

 package NodeList_p is new Double_Linked_List
 (
    Item       => Node_List_Item_t
 );

 type Seg_list_item_t is
  record
     From_Node  : NodeList_p := NodeList_p.null_list;
     To_Node    : NodeList_p := NodeList_p.null_list;
     altitude   : meters := 0.0;
     Seg_DB     : seg_t; -- a record having meaning in this context
  end record;

 package SegList_p is new Double_Linked_List
 (
    Item       => Seg_List_Item_t
 );

where the list package is defined as

 generic
    type Item is private;
 package Double_Linked_List is
    type List is private;
      (snip, snip)
 private
    type Node;
    type List is access Node;
    Null_List : constant List := null;
 end Double_Linked_List;

The question is, "What is the sequence of declarations in this mutually
recursive data structure that does not use unchecked_conversion and yet
gives clear visibility to a maintenance programmer, if this is possible
at all?"  I have previously used unchecked_conversion and this yields a
solution which is less-readable than I would prefer.

It would be simple, but invalid, to just put the incomplete type

  type SegList_p;

in front of the first declaration, as subsequent references are not
merely accesses, but require the prior instantiation of a generic.

Technical details:  Verdix compiler on a SPARCstation 10 under SunOS
moving to the latest Verdix compiler on a Sun/1000 under Solaris 2.x.

Regards, Mikey



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1994-11-02 17:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-02 17:40 Readable mutually recursive data structures? Michael Hagerty

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