[plt-scheme] Nested structures and inspectors

From: Dmitriy.Zavin at infineon.com (Dmitriy.Zavin at infineon.com)
Date: Fri Aug 13 16:58:27 EDT 2004

 >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

(define (struct->vector* s)
    (define (rec x)
      (if (struct? x)
          (struct->vector* x)
     (map rec
           (struct->vector s)))))



 >--dougo at place.org

Posted on the users mailing list.