[plt-scheme] inheritance of private fields?

From: Tom Sgouros (tomfool at as220.org)
Date: Fri Feb 29 07:45:19 EST 2008

Hello all:

I want to define a general class with some private fields that can be
used by subclass.  Here's a dumb example of what I thought would be the
right way to do this, but apparently isn't:

(define size% 
  (class* object% ()
    (public print-name print-age print-weight)

    (init-field (name 'Fred) (bday 070661)))

    (define age (calculate-age bday))
    (define weight 0)

    (define print-name (display name))
    (define print-age (display age))
    (define print-weight (display weight))


Now I want to be able to define a sub-class of this, so that age and
weight are available to definitions in that sub-class.  I haven't been
able to do that, so feel I must be missing something.

In the example age is a calculated value that depends on other
init-field values.  I'd make it public by putting it into the init-field
sequence, if there's a guarantee that the init-field entries are
processed in order (that it's a let* and not a let).  I can't find any
such guarantee in the documentation.  Failing that, what should I do to
make it available?

The weight private field should have no default value, but is intended
to be given one by the sub-class.  In my class-naif view of these
things, I should really make size% an interface and force the sub-class
to fill in the weight.  But I can't seem to figure out how to do that,

Can someone explain to me the proper way to deal with these issues?  Any
advice welcome.

Many thanks,


 tomfool at as220 dot org

Posted on the users mailing list.