OK, it works when the set! occurs after the super-new. I didn't think set! would work at all in a class definition (as opposed to within a method); I was thinking of the whole system of defining classes as more of a declarative DSL that only allowed certain constructs.<br>
<br>Now that you point it out though, I see there is an example in the guide that does set! on an inherited field.<br><br>Thanks,<br><br>Mark<br><br><div class="gmail_quote">On Wed, Dec 15, 2010 at 9:53 PM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">set!?<br>
<br>
Try it in both positions (the commented out one and the other one):<br>
the thing to keep in mind is that the declaration in c% is also kind<br>
of like a set! that happens when the object is initialized.<br>
<br>
Robby<br>
<br>
#lang racket<br>
(define c%<br>
(class object%<br>
(field [f 1])<br>
(define/public (get-f) f)<br>
(super-new)))<br>
<br>
(define d%<br>
(class c%<br>
(inherit-field f)<br>
(set! f 2)<br>
(super-new)<br>
; (set! f 2)<br>
))<br>
<br>
(send (new d%) get-f)<br>
<br>
On Wed, Dec 15, 2010 at 11:46 PM, Mark Engelberg<br>
<div><div></div><div class="h5"><<a href="mailto:mark.engelberg@gmail.com">mark.engelberg@gmail.com</a>> wrote:<br>
> Thanks. That seems to address the shared private issue.<br>
><br>
> So is there a way to give a new value to an inherited field?<br>
><br>
> --Mark<br>
><br>
> On Wed, Dec 15, 2010 at 9:13 PM, Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>><br>
> wrote:<br>
>><br>
>> See define-local-member-name.<br>
>><br>
>> Robby<br>
>><br>
>> On Wed, Dec 15, 2010 at 10:38 PM, Mark Engelberg<br>
>> <<a href="mailto:mark.engelberg@gmail.com">mark.engelberg@gmail.com</a>> wrote:<br>
>> > I'm playing around with the object-oriented subset of Racket, and have a<br>
>> > couple of questions.<br>
>> ><br>
>> > Ideally, I'd like to equip a class with a field that is visible only to<br>
>> > it<br>
>> > and its subclasses. As far as I can tell, though, this isn't possible.<br>
>> > It<br>
>> > seems that I have to make a choice between a completely private field<br>
>> > visible only to the class (by just using "define") or making a<br>
>> > completely<br>
>> > public field (by using "field"). Correct?<br>
>> ><br>
>> > Now, let's say I make the field public.<br>
>> ><br>
>> > In the subclass, how do I change the default value of field?<br>
>> ><br>
>> > For example, in the superclass, I might have<br>
>> > (field [a 300])<br>
>> ><br>
>> > but in the subclass, I want to do something like<br>
>> > (inherit-field [a 200])<br>
>> ><br>
>> > However, as far as I can tell, the syntax doesn't support anything other<br>
>> > than<br>
>> > (inherit-field a)<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> > Mark<br>
>> ><br>
>> > _________________________________________________<br>
>> > For list-related administrative tasks:<br>
>> > <a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>