[plt-scheme] Obtaining hierarchal info about structs

From: Bruce Hauman (bhauman at cs.wcu.edu)
Date: Fri Apr 25 09:26:32 EDT 2003

This is a repost of my previous question, but I give a much more
complete description of the problem.

I am just trying to get a list of super types for a structure
at expansion time.

I don't know if this is possible but it seems like it should be
given the supplied functions syntax-local-value and struct-type-info.
When syntax-local-value is applied to the syntax of a struct-name it
returns a list of information about that struct.  The first item in the
list is said to be "an identifier that is bound to the structure type's
descriptor, or #f it none is known."

I would like to use this identifier as an argument to struct-type-info
inorder to get at that excellent information.  But alas, the object
returned by syntax-local-value is a syntax object and I cannot seem to
coerce it into a form that is acceptable by struct-type-info.  Is this a
namespace problem?

Here is a complete example:

(define-struct universe () (make-inspector))
(define-struct (solar-sys universe) () (make-inspector))
(define-struct (planet solar-sys) () (make-inspector))
(define-struct (earth planet) () (make-inspector))
(define-struct (mountain earth) () (make-inspector))

(define-syntax (hier-chain stx)
  (syntax-case stx ()
    ((_ struct-name)
     (letrec ((struct-type-syntax-obj
               (list-ref
                (syntax-local-value
                 (syntax struct-name)) 0))
              (get-chain
               (lambda (struct-type)
                 (let-values (((name x y z q l super-type d)
                               (struct-type-info struct-type)))
                   (if super-type
                       (cons name (get-chain super-type))
                       '())))))
       ;; This is where it breaks down.  Some how I need to
       ;; translate struct-type-syntax-obj into a struct-type.
       #`(list #,@(get-chain
                    (syntax-object->datum struct-type-syntax-obj)))))))


(hier-chain mountain)
;; I am hoping that this will return
;; (mountain earth planet solar-sys universe)
;; or something like it


Am I on the right track here or am I way off?

Thanks,
Bruce Hauman



Posted on the users mailing list.