<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) ...) 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. </div><div><br></div><div>I thought you wanted something like 'friendly private', which requires a bit more work. </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. 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. 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"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></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>
(provide c% a)<br>
<br>
(define-local-member-name a b)<br>
<br>
(define c%<br>
(class object%<br>
(field [x 10])<br>
(super-new)<br>
(define/public (a) x)<br>
(define/public (b y) (set! x y)))))<br>
<br>
<br>
(module client racket<br>
(require (submod ".." server))<br>
<br>
(define c (new c%))<br>
<br>
(with-handlers ((exn:fail:object? (lambda (x) (displayln `(message not found)))))<br>
(send c b))<br>
(displayln (send c a)))<br>
<br>
(require 'client)<br>
<br>
I think you're looking for it. -- Matthias<br>
<div><div><br>
<br>
<br>
On May 30, 2013, at 3:05 PM, Sean Kanaley <<a href="mailto:skanaley@gmail.com" target="_blank">skanaley@gmail.com</a>> wrote:<br>
<br>
> In C++ for example, the following is valid:<br>
><br>
> class A {<br>
> private:<br>
> int test(A a) { return n + a.n; }<br>
> int n;<br>
> };<br>
><br>
> The key point is the "a.n" is valid.<br>
><br>
> 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>
> (define obj%<br>
> (class object% (super-new) (init ... [parent #f])<br>
> (define p parent)<br>
> (define cs '())<br>
> (when p (send p add-child! this))<br>
> (define/public (set-trans! new-t)<br>
> ... <includes delayed world-trans calc><br>
> (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>
> 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>> ____________________<br>
> Racket Users list:<br>
> <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>