On 9 May 2010, at 04:44, Mark Engelberg wrote:
In Python, let's say I have a library "mylibrary.py", and from various
files I say "from mylibrary import *".
If I want to split mylibrary.py into two parts, say, library1.py and
library2.py, then I can just change mylibrary.py to say:
from library1 import *
from library2 import *
Since you mention Python, there is one very important difference to
keep in mind: Clojure has a two-step symbol resolution, whereas
Python's is one-step. In other words, Clojure has one more level of
indirection.
In Python, a module (the closest equivalent to a Clojure namespace) is
a mapping from symbols to values. Defining a function or assigning to
a variable inside a module assigns a new value to a symbol, creating
it if necessary. Importing names from another modules has the same
result: values are assigned to symbols in the importing namespace.
In Clojure, there are symbols and vars where Python has just symbols.
A namespace has interned vars, which in a certain sense "belong" to
the namespace. def and its variants assign new values to interned
vars, creating them if necessary. But a namespace also has a mapping
from symbols to vars. A symbol can be mapped to a var in the same
namespace (the case of interned vars), or to a var in another
namespace. The latter kind of reference is created by :use in the ns
form.
The difference matters when the values of vars change, either by
redefinition or inside a binding form. In Python, an imported symbol
retains its value even when the symbol's definition in the original
namespace changes. In Clojure, a reference to another namespace's var
always reflects the current value of that var.
A while ago I wrote a blog post that goes into more detail on this
topic:
http://onclojure.com/2010/02/17/managing-namespaces/
I agree with your observations about difficulties with namespace
refactoring in Clojure, and I would like to see additional namespace
management options for the cases you mention. I am rather sure that
all of this can be done without any change to the fundamental
namespace mechanism, just by providing additional options/functions
for namespace management. I have started a small library for
exploring possibilities:
http://code.google.com/p/clj-nstools/
Comments and enhancements are always welcome.
Konrad.
--
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