(require 'ns-a)  will 'install' the namespace ns-a in the clojure
environment.  If ns-a has other namespaces that it requires ... they will
also be installed for ns-a to be fully functional.

(use 'ns-a) will not only 'install' the namespace ns-a, but also create
mappings for all public vars of namespace ns-a in the current namespace (the
mappings will have the same name as the vars in ns-a).

An example may help understand :

; file ns-b
(ns ns-b)
(defn b1 [] "importable")
(defn- b2 [] "non importable")

; file ns-a
(ns ns-a (:require ns-b))
(defn a1 [] (ns-b/b1))

; file ns-c
(ns ns-c (:use ns-a))
(defn c1 [] (b1))

;; and from the REPL
user> (require 'ns-b)
user> (b1)
==> wil generate an error since ns-a is just required (there is no a1
user> (ns-b/b1)
==> will work
user> (ns-b/b2)
==> will not work since b2 is namespace private
user> (use 'ns-b)
==> will work unless namespace 'user already has a var or mapping with name
b1
user> (b1)
==> will work, is now equivalent to (ns-b/b1)
user>(b2)
==> will not work, 'use does not create mappings for namespace private vars

HTH,

-- 
Laurent

2009/8/24 CuppoJava <patrickli_2...@hotmail.com>

>
> Laurent would you mind explaining what is the difference between
> require and use? I don't understand the documentation for those
> functions.
>
> Thanks a lot
>  -Patrick
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to