set!? Try it in both positions (the commented out one and the other one): the thing to keep in mind is that the declaration in c% is also kind of like a set! that happens when the object is initialized.
Robby #lang racket (define c% (class object% (field [f 1]) (define/public (get-f) f) (super-new))) (define d% (class c% (inherit-field f) (set! f 2) (super-new) ; (set! f 2) )) (send (new d%) get-f) On Wed, Dec 15, 2010 at 11:46 PM, Mark Engelberg <mark.engelb...@gmail.com> wrote: > Thanks. That seems to address the shared private issue. > > So is there a way to give a new value to an inherited field? > > --Mark > > On Wed, Dec 15, 2010 at 9:13 PM, Robby Findler <ro...@eecs.northwestern.edu> > wrote: >> >> See define-local-member-name. >> >> Robby >> >> On Wed, Dec 15, 2010 at 10:38 PM, Mark Engelberg >> <mark.engelb...@gmail.com> wrote: >> > I'm playing around with the object-oriented subset of Racket, and have a >> > couple of questions. >> > >> > Ideally, I'd like to equip a class with a field that is visible only to >> > it >> > and its subclasses. As far as I can tell, though, this isn't possible. >> > It >> > seems that I have to make a choice between a completely private field >> > visible only to the class (by just using "define") or making a >> > completely >> > public field (by using "field"). Correct? >> > >> > Now, let's say I make the field public. >> > >> > In the subclass, how do I change the default value of field? >> > >> > For example, in the superclass, I might have >> > (field [a 300]) >> > >> > but in the subclass, I want to do something like >> > (inherit-field [a 200]) >> > >> > However, as far as I can tell, the syntax doesn't support anything other >> > than >> > (inherit-field a) >> > >> > Thanks, >> > >> > Mark >> > >> > _________________________________________________ >> > For list-related administrative tasks: >> > http://lists.racket-lang.org/listinfo/users >> > > > _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/dev