[plt-scheme] class-info: class-names as strings

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jan 23 21:20:51 EST 2007

At Tue, 23 Jan 2007 12:07:34 +0000, Dave Gurnell wrote:
> I have a situation in one of my web apps where the class-name  
> procedure from class.ss returns a string as the "name-symbol" return  
> value rather than a symbol as documented. The name is of the format  
> "derived-from-some-superclass%", and the class is an anonymous subclass.
> I haven't been able to create a test-case where I get a name in this  
> format yet.

I'm not following completely. I think you're asking about
`object-name', which should indeed return a symbol for classes and
instances of classes, and always does as far as I can tell.

A 'derived-from-...' name is created when there's no inferred name or
source location for a `class' expression.

To get that kind of name, the main trick is to not have a source
location. One way to avoid source locations is to use `eval':

 > (define c% (class object% (super-new)))
 > (eval '(class c% (super-new)))

Another way is to have the `class' form generated by a macro, and
compile the macro to ".zo" (since source locations are not preserved
for quoted syntax in a ".zo" file). Given the file "m.ss":

  (module m mzscheme
    (require (lib "class.ss"))
    (provide klass)

    (define-syntax klass
      (syntax-rules ()
        [(_ b ...)
         ;; The extra `let' avoids propagating the
         ;;  location of the `klass' use to `class':
         (let () (class b ...))])))

compiled to .zo with mzc:

 mzc --make m.ss


 > (require "m.ss")
 > (require (lib "class.ss"))
 > (define c% (klass object% (super-new)))
 > (klass c% (super-new))


Posted on the users mailing list.