[plt-scheme] How get name of structure

From: jos koot (jos.koot at telefonica.net)
Date: Wed Apr 11 04:59:56 EDT 2007

Or better allow f to work for structs controlled by the current inspector too:

(define-struct structure1 (f1) (make-inspector))
(define-struct structure2 (f1 f2))
(define x (make-structure1 1))
(define y (make-structure2 'a 'b))

(define (f x)
 (parameterize ((print-struct #f))
  (printf "Name of structure ~a~n"
   (regexp-replace* "^.*<struct:|>$" (format "~s" x) ""))))

(f x) ; displays Name of structure structure1
(f y) ; displays Name of structure structure2

Jos Koot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070411/ff8655b2/attachment.html>

Posted on the users mailing list.