<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Oh, if all you want is completely private methods, then use (define/private (m x) ...) &nbsp;or even plain (define (m x) ...) The latter defines a private field that contains a closure, and you can mutate this field; the former is really a private method and does not consume space in the object.&nbsp;</div><div><br></div><div>I thought you wanted something like 'friendly private', which requires a bit more work.&nbsp;</div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><br><div><div>On May 30, 2013, at 7:15 PM, Sean Kanaley wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">This seems like it could work, however if my understanding is correct that any class that wishes C++-style private access has to wrap the class in a module and expose everything except the specific things it's trying to hide, well that seems much more difficult than some sort of define/private that works as C++/Java/C# etc. does.&nbsp; Perhaps such a feature is not easy to implement, so I don't mean too come across badly, but such a feature would be awfully nice.&nbsp; Maybe if I feel inspired I can look at the source and try to implement it.<br>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 30, 2013 at 5:16 PM, Matthias Felleisen <span dir="ltr">&lt;<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Do you know about define-local-member-name?<br>
<br>
#lang racket<br>
<br>
(module server racket<br>
<br>
&nbsp; (provide c% a)<br>
<br>
&nbsp; (define-local-member-name a b)<br>
<br>
&nbsp; (define c%<br>
&nbsp; &nbsp; (class object%<br>
&nbsp; &nbsp; &nbsp; (field [x 10])<br>
&nbsp; &nbsp; &nbsp; (super-new)<br>
&nbsp; &nbsp; &nbsp; (define/public (a) x)<br>
&nbsp; &nbsp; &nbsp; (define/public (b y) (set! x y)))))<br>
<br>
<br>
(module client racket<br>
&nbsp; (require (submod ".." server))<br>
<br>
&nbsp; (define c (new c%))<br>
<br>
&nbsp; (with-handlers ((exn:fail:object? (lambda (x) (displayln `(message not found)))))<br>
&nbsp; &nbsp; (send c b))<br>
&nbsp; (displayln (send c a)))<br>
<br>
(require 'client)<br>
<br>
&nbsp;I think you're looking for it. -- Matthias<br>
<div><div><br>
<br>
<br>
On May 30, 2013, at 3:05 PM, Sean Kanaley &lt;<a href="mailto:skanaley@gmail.com" target="_blank">skanaley@gmail.com</a>&gt; wrote:<br>
<br>
&gt; In C++ for example, the following is valid:<br>
&gt;<br>
&gt; class A {<br>
&gt; private:<br>
&gt; &nbsp; &nbsp; int test(A a) { return n + a.n; }<br>
&gt; &nbsp; &nbsp; int n;<br>
&gt; };<br>
&gt;<br>
&gt; The key point is the "a.n" is valid.<br>
&gt;<br>
&gt; 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>


&gt;<br>
&gt; (define obj%<br>
&gt; &nbsp; (class object% (super-new) (init ... [parent #f])<br>
&gt; &nbsp; &nbsp; (define p parent)<br>
&gt; &nbsp; &nbsp; (define cs '())<br>
&gt; &nbsp; &nbsp; (when p (send p add-child! this))<br>
&gt; &nbsp; &nbsp; (define/public (set-trans! new-t)<br>
&gt; &nbsp; &nbsp; &nbsp; ... &lt;includes delayed world-trans calc&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; (for ([c cs])<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; (send c set-trans! (send c local-trans))))<br>
&gt; &nbsp; &nbsp; ...<br>
&gt; &nbsp; &nbsp; (define/public/private/etc. (add-child! c) (set! cs (cons c cs)))))<br>
&gt;<br>
&gt; It obviously works with "define/public", but I'm hoping there is a way to not expose the method everywhere. &nbsp;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>&gt; ____________________<br>
&gt; &nbsp;Racket Users list:<br>
&gt; &nbsp;<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div><br></div></div>
</blockquote></div><br></body></html>