"Meikel Brandmeyer" <m...@kotka.de> said: > On May 31, 10:58 am, "Sina K. Heshmati" <s...@khakbaz.com> wrote: > >> foo.datatype-01 => (reset! state 13) > ^^^^^^^^^^^^^^^ > > Again: of course you can! You are in the same namespace! In Clojure > the "unit" is a namespace and not a type. If you want this level > privateness you have to use one namespace per type. However this is > not really the Clojure Way.
Here's my concern: - My program (A) is running. - B is running on the same VM. - B accesses the state of A. - B alters the state of A in an inconsistent way e.g. whenever the internal state x changes, the internal state y also has to change accordingly, but B only changes x. - A is screwed. The author of Clojure calls encapsulation a folly but I don't understand why (?) How can we avoid situations like the one explained above? I came up with the following, which does what I want by relying on the lexical scope of functions. This is OK but the only problem is the fact that I have to hardcode function calls for each type method. (defprotocol prot-a (op-a [self x y])) (let [state (atom 10)] (defn op-a [self x y] (+ x y (.member self) @state))) (deftype t-a [member] prot-a (op-a [self x y] (op-a self x y))) (def t-a-1 (t-a. 5)) Is there a way to pass the function itself rather than making a new function that calls the exact same function with the same arguments? Kind regards, SinDoc -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en