Hi, On 10 Mai, 00:15, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> The more I think about this, the more I feel like I don't have a good mental > model of what's going on with namespaces/loading/reading/compiling. What is > happening when you "load" a file without reading/compiling it (e.g., > load-reader or load-file)? How does referring/using match up with those > low-level concepts? Clojure's view of the world is actually quite easy: it read forms from the input, compiles and evaluates them. That's it. Really! Consider the following file: (ns foo.bar) (require '[foo.baz :as baz]) (defn frobnicator [flogiston-reactor] (baz/do-frobnication flogiston-reactor)) What does happen here? Easy! Clojure reads the file and first gets the ns declaration back from the Reader. It creates the foo.bar namespace if necessary and does any require/use/import things. Then it reads the next form: require. It gets compiled and evaluated. That is, it tries to load the foo.baz namespace and - if successful - sets up an namespace alias by virtue of the alias function. Next it reads frobnicator and sets up the Var and the function it contains. That's all. Nothing more. You can see this by moving the frobnicator call above the require and see the load fail. (In a fresh Repl of course) The same happens whether you load it from the classpath or via load-file. Put things in a file-named-independent-from-foo.bar.clj and load it via load-file: it will still work. Put things in a String and use a StringReader and things will still work. Namespace vs. name of file convention just helps finding things on the classpath. And this is same in Python, Ruby, OCaml, etc. Require and friends just set up what *this* namespace needs. I think, 95% of the use cases for immigrate should probably read load. Hope that helps. 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 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