PS: racket's class system has classes-as-values and some of the things that are allowed in those language depend on first-order classes (like that feature) and that extra power that you get means that some things come in different ways that you're expecting. FWIW.<div>
<br></div><div>Robby<br><div><div><br>On Thursday, May 30, 2013, Sean Kanaley wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes but that only works for "this". It's basically (send this method args ...) == (method args ...). I wish to call the method on a <i>different</i> object of the same class. C++/Java/C# etc. all allow access to private data in "sibling" objects.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 30, 2013 at 7:09 PM, Robby Findler <span dir="ltr"><<a href="javascript:_e({}, 'cvml', 'robby@eecs.northwestern.edu');" target="_blank">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">When you are inside a class, you don't use send. You just call the method with a regular function-application looking syntax.<div>
<br></div><div><div>#lang racket</div><div>(define c%</div><div> (class object%</div><div>
(define/public (m x)</div><div> (printf "n on ~s is ~s\n" x (n x)))</div><div> (define/private (n x)</div><div> (* x x))</div><div> (super-new)))</div><div><br></div><div>(send (new c%) m 11)</div>
<span><font color="#888888">
</font></span></div><span><font color="#888888"><div><br></div><div><br></div></font></span><div><span><font color="#888888">Robby</font></span><div><div><br><br>On Thursday, May 30, 2013, Sean Kanaley wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div><div><div><div><div><div><div><div>In C++ for example, the following is valid:<br><br></div>class A {<br></div>private:<br></div> int test(A a) { return n + a.n; }<br></div> int n;<br>};<br><br></div>
The key point is the "a.n" is valid.<br><br></div>I'm trying to create a 3d game in Racket, and in order to avoid recomputing world transforms all the time, child objects (say a rotatable gun on a parent tank) take a parameter to their parent which is used to add the child ("this") to the parent, in order that the parent update a delayed world transform computation in case of multiple calls to set-trans!, roughly:<br>
<br></div>(define obj%<br> (class object% (super-new) (init ... [parent #f])<br></div><div> (define p parent)<br> (define cs '())<br> (when p (send p add-child! this))<br> (define/public (set-trans! new-t)<br>
</div><div> ... <includes delayed world-trans calc><br></div><div> (for ([c cs])<br> (send c set-trans! (send c local-trans))))<br> ...<br> (define/public/private/etc. (add-child! c) (set! cs (cons c cs)))))<br>
<br></div><div>It obviously works with "define/public", but I'm hoping there is a way to not expose the method everywhere. It's in essence private, but Racket seems to not allow access even from within the class (send complains "no such method").<br>
</div></div>
</blockquote></div></div></div>
</blockquote></div><br></div>
</blockquote></div></div></div>