Does 'define' really mean 'make a field'? I thought fields had to be specially designated so that get-field would know about them...<div><br></div><div>Yes, this program errors:</div><div><br></div><div><div>
#lang racket</div><div><br></div><div>(define c%</div><div> (class* object% ()</div><div> (field [x 1])</div><div> (define y 2)</div><div> (super-new)))</div><div><br></div><div>(define o (new c%))</div><div><br>
</div><div>(field-names o)</div><div>(get-field x o)</div><div>(get-field y o)</div><div><br></div><div>--</div><div><br></div><div>I agree that 'define' is like making a field, but fields are something special too.</div>
<div><br></div><div>Jay</div><br><div class="gmail_quote">On Thu, Dec 16, 2010 at 6:51 AM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Thu, Dec 16, 2010 at 12:22 AM, Mark Engelberg<br>
<div class="im"><<a href="mailto:mark.engelberg@gmail.com">mark.engelberg@gmail.com</a>> wrote:<br>
</div>> OK, it works when the set! occurs after the super-new. I didn't think set!<br>
> would work at all in a class definition (as opposed to within a method); I<br>
> was thinking of the whole system of defining classes as more of a<br>
> declarative DSL that only allowed certain constructs.<br>
<br>
You've probably already figured this out, but the body of a class is a<br>
series of definitions and expressions like at the top-level but<br>
'define' taking on the meaning of 'make a field', and a bunch of new<br>
definitions appearing. The new stuff says what the methods are, but<br>
everything else is just executed in sequence as if it were in the body<br>
of the initializer (if this were in Java, say).<br>
<br>
hth,<br>
<font color="#888888">Robby<br>
</font><div><div></div><div class="h5">_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/dev" target="_blank">http://lists.racket-lang.org/listinfo/dev</a></div></div></blockquote></div><br><br clear="all"><br>-- <br>Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br><br>"The glory of God is Intelligence" - D&C 93<br>
</div>