[comp.lang.misc] Mutually recursive data structs

jlg@lambda.UUCP (Jim Giles) (02/24/90)

From article <1990Feb23.211123.17676@umn-cs.cs.umn.edu>, by mike@umn-cs.cs.umn.edu (Mike Haertel):
> [...]
> My one question is:  How do you do mutually recursive data structures,
> rather than just diretly recursive ones?

How about the obvious:
              type mutual1 is recursive
                 node   value
                 mutual2 link
              end type mutual1

              type mutual2 is recursive
                 node   value
                 mutual1 link
              end type mutual2

              mutual1 x = null
              mutual2 y = {1,null}
               ...
              y.link = x
              x.value = 2
              x.link = y
               ...

This list is circular.  Both x and y are on the list (and nothing else
so far).  The list alternates between 'mutual1' and 'mutual2' data
types.  This would probably be hard to code with, but the difficulties
would all have to do with remembering the parity of the list, not
with the syntax of the language.

J. Giles