[plt-scheme] Nested structures and inspectors
>Dmitriy.Zavin at infineon.com writes:
> > (define foobar (make-foo 'a 'b 'c (make-bar 'e 'f 'g 'h)))
> > (struct->vector foobar)
> >
> > Now what I expected was to see the actual vector with all
>the nested
> > structure info expanded, i.e.
> > #5(struct:foo a b c #5(struct:bar e f g h))
> >
> > However, what I got is this:
> > #5(struct:foo a b c #<struct:bar>)
>
>Quick guess-- it looks like you need to call struct->vector
>recursively on the output vector, otherwise you just get a vector that
>contains structs (rather than a vector that contains vectors).
>
Yeah, that's exactly what I needed.
Thanks to floppydisk on #scheme for this gem. All you need to do is
this:
(define (struct->vector* s)
(define (rec x)
(if (struct? x)
(struct->vector* x)
x))
(list->vector
(map rec
(vector->list
(struct->vector s)))))
Thanks.
--Dima
>--dougo at place.org
>