From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b7dc7082d345b1e1 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: package dependence question Date: 2000/05/30 Message-ID: #1/1 X-Deja-AN: 629078530 Sender: bobduff@world.std.com (Robert A Duff) References: <8gt19i$1cm8@r02n01.cac.psu.edu> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-05-30T00:00:00+00:00 List-Id: Carl Banks writes: > My question is, is there a better way to define such a doubly- > traversible tree, so that different node types need not be defined in > the same package? There is no ideal solution to this problem in Ada 95 (although the ARG is currently working on a language modification that will solve the problem nicely). One thing you can do is declare tagged type Node, and then "type Node_Ptr is access all Node'Class;". Make types A, B, and C derive from Node. Then B can have a component like "Parent: Node_Ptr;". You lose type checking -- the parent of a B is always an A, but the code doesn't say so, except in a comment. Another way to have mutually-recursive types is to create a dummy parent type for one or more of the types. Eg, if you have X and Y that point to each other, you can declare Dummy_X and Dummy_Y as null records, and point to Dummy_X'Class and Dummy_Y'Class. Then X is derived from Dummy_X, adding the actual record components. Similarly for Y. - Bob