[plt-scheme] same names for class.ss init-fields and methods

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Wed Mar 26 10:09:59 EST 2003

In `class*' syntax, is there a way to define public methods that have
the same names as initialization fields?

Basically, I'd like users to be able to use syntax like:

    (define o (instantiate c% () (foo 42) (bar 69)))

and also use those same names as messages to retrieve what are (from the
user's perspective) simple attribute values:

    (send o foo)
    (send o bar)

Note that `foo' and `bar' methods don't necessarily simply return field
values -- they might first have to restore some data consistency within
the object (such as when we have a pair of mutually derivable attributes
that can be set independently and are expensive to compute).

Currently I just prepend `get-' to these method names, to avoid name
conflicts within `class*':

    (send o get-foo)
    (send o get-bar)

This makes for a lot of "get-" in the user code -- both because of name
conflicts in the `class*' implementation, and because designers of class
interfaces might prefix most conceptual attribute value getter method
names with "get-" to avoid prejudicing implementations as to which
attributes should be fields.  (Of course, particular implementations of
the interface may expose some init-fields, but I think that's a separate


Posted on the users mailing list.