[plt-scheme] building mutually recursive structs

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Jul 20 16:54:55 EDT 2004

On Jul 20, 2004, at 1:14 PM, David A. Herman wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> What's the most Schemely idiom for building structs with graph 
> structure?
> The most Java-like solution would be to make the accessors functions. 
> The
> Haskellish solution would be to use delay and force. The C solution 
> would
> probably be to run two passes, first creating the objects and then 
> filling
> in the back-pointers.

The Scheme way is to use one of the three methods. The one you like 

> I actually prefer the latter, because it requires the least extra work 
> of
> the client: once the data structure is created, you just use the normal
> accessors. But I'm not sure how to abstract over the pattern. I.e., I'd
> like a form that does things like:
>   (define-struct thing (parent value children))
>   (letrec-data ([root (make-thing #f 0 (list (make-thing root 1 null)
>                                              (make-thing root 2 null)
>                                              (make-thing root 3 
> null)))])
>   root)
>   =>
>   (let ([root (make-thing #f 0 (list (make-thing 'hukairs 1 null)
>                                      (make-thing 'hukairs 2 null)
>                                      (make-thing 'hukairs 3 null)))])
>     (set-thing-parent! (car (thing-children root)))
>     (set-thing-parent! (cadr (thing-children root)))
>     (set-thing-parent! (caddr (thing-children root))))
> I suppose I could write a function that traverses all structs and lists
> within structs, but this is slow and ungeneral.

Use share. ?

-- Matthias

Posted on the users mailing list.