[racket] Calling Private Methods on non-this Objects?
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.
I thought you wanted something like 'friendly private', which requires a bit more work.
-- Matthias
On May 30, 2013, at 7:15 PM, Sean Kanaley wrote:
> 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.
>
>
> On Thu, May 30, 2013 at 5:16 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> Do you know about define-local-member-name?
>
> #lang racket
>
> (module server racket
>
> (provide c% a)
>
> (define-local-member-name a b)
>
> (define c%
> (class object%
> (field [x 10])
> (super-new)
> (define/public (a) x)
> (define/public (b y) (set! x y)))))
>
>
> (module client racket
> (require (submod ".." server))
>
> (define c (new c%))
>
> (with-handlers ((exn:fail:object? (lambda (x) (displayln `(message not found)))))
> (send c b))
> (displayln (send c a)))
>
> (require 'client)
>
> I think you're looking for it. -- Matthias
>
>
>
> On May 30, 2013, at 3:05 PM, Sean Kanaley <skanaley at gmail.com> wrote:
>
> > In C++ for example, the following is valid:
> >
> > class A {
> > private:
> > int test(A a) { return n + a.n; }
> > int n;
> > };
> >
> > The key point is the "a.n" is valid.
> >
> > 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:
> >
> > (define obj%
> > (class object% (super-new) (init ... [parent #f])
> > (define p parent)
> > (define cs '())
> > (when p (send p add-child! this))
> > (define/public (set-trans! new-t)
> > ... <includes delayed world-trans calc>
> > (for ([c cs])
> > (send c set-trans! (send c local-trans))))
> > ...
> > (define/public/private/etc. (add-child! c) (set! cs (cons c cs)))))
> >
> > 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").
> > ____________________
> > Racket Users list:
> > http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130530/8087c970/attachment.html>