On Mon, Nov 15, 2010 at 2:35 PM, trying clj <trying...@gmail.com> wrote: > File example\some.clj > > (ns example.some (:use example.someother)) > > (defn helloworld [] (print "helloworld")) > > > File example\someother.clj: > > (ns example.someother (:use example.some)) > > (defn sample [] (helloworld)) > > > A compile error "Unable to resolve helloworld in this context" is produced > (on either latest clojure-maven-plugin or Leiningen). If the two defn's are > switched places, the build completes successfully. > > This is very basic functionality but after thinking a lot, I still see no > reason why it isn't working. What am I getting wrong?
Probably in one case it was compiling the file with sample before the file with helloworld. Be glad this example doesn't have a true circular dependency. I have sometimes resorted to atom to get rid of circular dependencies: file1.clj: (defvar- foo (atom nil)) (defn some-fn [...] ... (do-something-with @foo) ...) (defn set-foo! [x] (reset! foo x)) file2.clj: (defn some-other-fn [...] ... (some-fn some-args) ...) (defn init-file2 [] (set-foo! [some-data-structure-built-using-some-other-fn])) filen.clj: (defn main- [...] (init-file2) ...) Obviously in this example some-fn ought to have some way to be somewhat useful if the atom's still its initial value, here nil. A case that comes up sometimes is a lookup table, in which case starting it with an empty map {} makes sense. The most recent case where I did something like this, foo was a large data structure that had to hold functions that called functions that called functions that, eventually, referenced the data structure. None of these functions would actually get *called* until bootstrap was complete, so they'd never see the atom holding nil, but fn1 calls fn2 calls fn3 calls fn4 references foo contains fn1 is still a circular dependency. -- 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