I spent the past half-hour experimenting with what happens in Clojure if the ns declaration doesn't match the file name, and what happens if the ns declaration is not at the top of the file.
Here's what I've found so far: 1. When you require/use/load a file, Clojure finds it by the filename. 2. If your ns declaration does not match the filename, Clojure happily goes ahead and puts any definitions that follow the ns declaration inside the namespace named by the ns. 3. If you have no ns declaration, then the code in the file gets loaded into the namespace of the file which is requiring it. 4. If the ns declaration is not at the top of the file, then the code above the ns declaration gets loaded into the namespace of the file which is requiring it, and the code after it goes into whatever namespace is specified by the ns declaration. 5. I am unable to find any difference (other than syntax) between requiring a file and loading it. Is there any difference? (Perhaps if you load vs. require the same file from two other files, there's a difference?) I'm still not having much luck loading another file using a path relative to the location of the file that is doing the requiring, and don't know if that's supposed to be possible. Everything seems to be relative to the root of the part of the classpath containing the requiring file. So what are some good examples of why you'd want to do any of these funky things, e.g., using namespaces that don't match the filenames, putting namespace declarations in the middle or omitting them entirely? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. 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
