[plt-scheme] Accessing class in method?

From: Sam Phillips (samdphillips at gmail.com)
Date: Tue Oct 7 20:14:32 EDT 2008

On Tue, Oct 7, 2008 at 4:23 PM, Carl Eastlund <cce at ccs.neu.edu> wrote:
> Off the top of my head there are two ways to go about this, neither perfect.
> One is the OO method: have B override A.  Any subclass of A will have
> to do this.  The drawback: lots of duplicated code, and it goes wrong
> if you forget to override somewhere.

I pretty much had discarded this solution for the exact reasons you said.

> The other is reflection: use object-info in the make method to extract
> the class of the current object.  The drawback: not only is
> object-info not guaranteed to be able to access the class of the
> current object, but you have no guarantee your subclasses don't
> introduce constructor arguments you don't know about.

I saw object-info, but wasn't sure if there was a better way of doing

> This isn't an easy problem, much as it seems like it should be;
> because subclasses have so much power to change their behavior,
> automatically generating factory methods for them is nontrivial.
> Choosing the best way to solve this will depend a lot on what you're
> trying to do with your factory method and the structure of your
> classes.  If you have more specific information, post it and maybe
> someone can help you narrow down a better solution.

I was mostly curious coming from a Smalltalk/Python background and
being new to the PLT class system.  Both Smalltalk and Python let you
get a hold of the current class and from there call methods on it (like
constructors.)  From what little I remember from swindle/tinyclos you
can do something similar with those systems.


Posted on the users mailing list.