Re: gen-class and namespace
Hi, >> gen-class loads eg. foo/bar/Baz.clj for class foo.bar.Baz. However, >> maybe one also has support functions in the foo.bar namespace. Hence >> one needs also foo/bar/bar.clj. > > I seem to be able to solve the problem by putting this at the top of > Baz.clj: > > (ns foo.bar (:use foo.bar)) > > That causes foo/bar/bar.clj to be loaded the first time its needed and > not again. Is that what you want? I'm probably misunderstanding the > problem, so feel free to correct me. - You understand me correctly. - That works? I didn't even try. I was under the impression, that there was some cycle detection implemented in use and require. So I would have expected this to fail... For me this feels fishy, because: - Why does the user have to do crazy looking stuff? (defining a namespace requiring itself?) - I have to be concerned about load'ing Baz.clj in bar.clj. If there is no cycle detection, I'm in trouble. So I have to inform myself about unrelated implementation details. - It is inconsistent to the "namespace matters, not file" philosophy advocated previously. I could also just put "(require 'foo.bar)" in Bar.clj and put the implementation somewhere else. That would solve the problem also, but why does the user have to provide boilerplate, when this could be done automatically? Your solution solves my problem, but to be honest: to me it looks not less hacky... Sincerely Meikel --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: gen-class and namespace
On Wed, Oct 8, 2008 at 5:32 PM, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote: > > gen-class loads eg. foo/bar/Baz.clj for class foo.bar.Baz. However, > maybe one also has support functions in the foo.bar namespace. Hence one > needs also foo/bar/bar.clj. I seem to be able to solve the problem by putting this at the top of Baz.clj: (ns foo.bar (:use foo.bar)) That causes foo/bar/bar.clj to be loaded the first time its needed and not again. Is that what you want? I'm probably misunderstanding the problem, so feel free to correct me. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
gen-class and namespace
Dear Clojurians, gen-class loads eg. foo/bar/Baz.clj for class foo.bar.Baz. However, maybe one also has support functions in the foo.bar namespace. Hence one needs also foo/bar/bar.clj. But now we are in trouble, since we have to duplicate any shared initialisation between bar.clj and Baz.clj. We cannot ensure, that the user "require"s the namespace before creating a new Baz object. As Rich stated in other threads: the unit that matters is the namespace, not the file. So I think gen-class should also require the namespace not the file. I tried to implement this, but this since my knowledge of such low-level stuff is nearly non-existant, it's more a hack. It extracts the namespace and loads the corresponding file, foo/bar/bar.clj in the above example. The namespace foo.bar is then in charge to provide the implementation for foo.bar.Baz. I tried to "require" the namespace, but I don't know enough of the gen stuff. But since the original gen-class also uses loadResourceScript I can live with that... The patch is (hopefully) attached. Comments appreciated. Sincerely Meikel gen-class-require.patch Description: Binary data smime.p7s Description: S/MIME cryptographic signature