Hi Meikel, Meikel Brandmeyer wrote: > Am 30.05.2010 um 16:39 schrieb Sina K. Heshmati: > >> [2] >> http://github.com/sindoc/algorithms/blob/master/src/test/clojure/whiteboard/y2010/hide-adt-state-using-closure.clj > > I'm almost sure, that this code does not what you expect. Nested def's, and > in > particular defn's, are almost surely wrong. You want: > > (defn make-module > [] > (let [state (atom 0) > say-hello (fn [] (println "Hello")) > public-op (fn [x y] (+ @state x y))] > (fn [op] > (case op > :hello say-hello > :public public-op))))
Could you elaborate a bit please? Is there a reason why nested defns are wrong? > And I'm not sure with what you mean by "you are not allowed to change the > root of > a Var". Of course you can do that. I referred to the fact that we can't do as follows: > (def x 10) > (set! x (* x x)) It should be possible to achieve the exact same effect using some other means but not as a result of evaluating the two expressions above. > (declare x) > (defn fn-using-x ...) > (def x 5) > > The declare is also (more or less) equivalent to (def x nil). (declare symbol) seems to work [3]. I'll later try it with deftypes to see if I can also export datatypes since my method as in [2] failed to export datatypes. Thank you Meikel. Kind regards, SinDoc [3] http://gist.github.com/419568 -- 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