[plt-scheme] Reflection in class.ss

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Fri Mar 30 05:16:10 EDT 2007

Ah! field-accessor-proc is returned by class-info. I understand where  
the individual class inspectors come into play now (I must've been  
tired yesterday or something).

Many Thanks,

-- Dave

> Yeah, get-runtime-field wasn't handling inheritance, and it wasn't  
> doing any kind of error trapping.  Here's one version that tries to  
> do so, although it hasn't been tested:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>   ;; get-runtime-field: object symbol -> any
>   ;; Tries to get the field value from the object.
>   ;; We must be able to inspect the class, or else this fails.
>   (define (get-runtime-field obj name)
>     (let-values ([(class skipped) (object-info obj)])
>       (let loop ([class class])
>         (unless class
>           (error 'get-runtime-field "can't inpect class for ~s" obj))
>         (let*-values ([(name-symbol
>                         field-k
>                         field-name-list
>                         field-accessor-proc
>                         field-mutator-proc
>                         super-class
>                         skipped)
>                        (class-info class)]
>                       [(index) (list-index (lambda (x) (eq? x name))
>                                            field-name-list)])
>           (cond
>             [(not index)
>              (error 'get-runtime-field "unknown field ~s" name)]
>             [(>= index field-k)
>              (loop super-class)]
>             [else
>              (field-accessor-proc obj index)])))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Posted on the users mailing list.