[plt-scheme] inheritance of private fields?

From: tom sgouros (tomfool at as220.org)
Date: Fri Feb 29 15:29:43 EST 2008

Hello all:

Here's a maybe simpler version of my question.  This code does what I
want it to do, except that I can't seem to redefine the inherited weight
field.  define doesn't do it, and set! doesn't do it, and inherit-field
chokes when I try (inherit-field (weight 3)).  There must be something I
can use on the >>>> line below, but what?

I'm sure I'm being stupid here, but I really don't know what else to
try, and don't really understand why what I've tried doesn't work.  I've
asked that the field be inherited, why doesn't that make the name
available within the fsize% definition?

Also, *is* the order guaranteed in init-field?

Many thanks for the help,


(define size%
  (class* object% ()
    (public print-name print-age print-weight)
     (init-field (name 'Fred) (bday 070661))
     (field (weight 0))
     (define age (calculate-age bday))
    (define (print-name) (display name))
    (define (print-age) (display age))
    (define (print-weight) (display weight))

(define (calculate-age n) 33)

(define fsize%
  (class* size% ()
    (inherit print-name print-age print-weight)
      (inherit-field weight)
>>>>        (set! weight 3)

(define g (new size% (name 'Bert) (bday 45)))
(define h (new fsize% (name 'Susan) (bday 43)))

(send g print-name)
(send h print-name)
(send g print-weight)
(send h print-weight)

 tomfool at as220 dot org

Posted on the users mailing list.