[plt-scheme] using interfaces for inferred class print names

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Tue Mar 25 11:33:54 EST 2003

Now that i'm using mixins extensively, I'm finding that few of my
classes have inferrable names that can be used for the print
representation.  When the name cannot be inferred, it uses the source
position of the producing `class*' or `mixin' syntax:

    (define a% (class* object% ()))
    a%
    ==> #<struct:class:a%>

    (define b% (let ((some-local-name (class* object% ()))) some-local-name))
    b%
    ==> #<struct:class:some-local-name>

    (define c% (car (cons (class* object% ()) #f)))
    c%
    ==> #<struct:|class:#<struct:object:/home/neil/plt/collects/stepper/stepper-tool.ss:479:9>:9:23|>

    (define (make-some-class) (class* object% ()))
    (define d% (make-some-class))
    d% 
    ==> #<struct:|class:#<struct:object:/home/neil/plt/collects/stepper/stepper-tool.ss:479:9>:12:27|>

The drawback to source position information is that a given mixin might
be applied last to many different class derivations, so knowing the
mixin doesn't help distinguish the different resulting classes.

In absence of an inferrable class name from a top-level binding, what'd
often be more helpful than know a local name or a mixin syntax source
position is knowing the (minimal) set of interfaces that characterize
the class.  For example:

    (define a<%> (interface ()))
    (define b<%> (interface ()))
    (define c<%> (interface (a<%>)))
    (define d<%> (interface (b<%> c<%>)))

    (class* object% (a<%>))                ; #<class:(a<%>)>

    (class* object% (a<%> b<%> c<%>))      ; #<class:(b<%> c<%>)>

    (class* object% (a<%> b<%> c<%> d<%>)) ; #<class:(d<%>)>

Names of interfaces themselves are easily inferrable in all the cases
I've seen so far.  There is a little bit of unpleasantness, especially
during interactive programming, when interfaces bindings are redefined,
and a given class can have distinct interfaces with the same name, but
that's pathological enough to be tolerable.

Just an idea.

-- 
                                             http://www.neilvandyke.org/


Posted on the users mailing list.