This would make an excellent FAQ question and answer!

On Sat, Dec 20, 2008 at 9:53 AM, Stuart Sierra
<the.stuart.sie...@gmail.com>wrote:

>
> This might make a good FAQ question:
>
> On Dec 20, 11:25 am, chris <cnuern...@gmail.com> wrote:
> > I am unclear as to the difference between refer, import use, and require.
>
> Hi Chris,
>
> require: Load a Clojure library from a file on classpath.  Use this
> when you want to load a library, but leave it in its own namespace.
>
> refer: Bring public symbols from one namespace into the current
> namespace.  Use this when a library has already been loaded (example:
> clojure.set) but you want to use its public symbols without a
> namespace qualifier.
>
> import: Copy Java class names into current namespace.  Use this when
> you want to use a Java class without typing the full package name.
>
> use: Combination of require and refer.  Use this when you want to load
> a library AND use its symbols without a namespace qualifier.
>
> All four are available as keyword arguments to "ns", which is the
> preferred way to use them:
>
> (ns foo.bar
>  (:use my.little.lib)
>  (:require clojure.contrib.duck-streams)
>  (:import (java.io File InputStream))
>  (:refer clojure.set))
>
> ":require" also allows aliasing, like this:
> (ns foo.bar
>  (:require [clojure.set :as set]))
>
> Now you can write the symbol "clojure.set/union" as "set/union".
>
> -Stuart Sierra
> >
>

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