The only succinct documentation of namespaces I found on Clojure is
here. To quote Brian there:
> Hi,
> just started looking at Clojure, and it looks promising as a modern-
> day Lisp for practical use.
> I saw this presentation on Clojure: http://clojure.blip.tv/ and I
> wholeheartedly agree with the design principles. Unified access to all
> kinds of collections (list, array, struct, hash) is something I sorely
> missed in CL back in the day (late 90's), and I like the focus on
> practical programming in the modern world (multicore/multithread,
> leveraging existing libraries, a stable and mature VM plaform etc.).
> Looking forward to getting to know Clojure better.
> But I have a question: Why are there *four* ways to do an import, each
> with slightly different syntax and semantics?
:refer shouldn't be used by you at all.
:import brings in java classes
:use brings in the names from another clojure namespace without requiring namespace qualifications
:require brings in the names from another clojure namespace requiring namespace qualifications.
So if ns foo has a var bar, if you do (use 'foo), you can just refer to bar, but if you do (require 'foo), you have to say foo/bar, not just bar.
I should add: make sure file names do not include the "-" character even if the namespace you define with
(ns ...)
has a "-" character in it; replace it with a "_" instead in the file name (the namespace can continue to use the "-" though).
(edit: I will write
more about namespaces, especially the syntax of the
(ns ...)
later.)
No comments:
Post a Comment