1.3.0 permalink Arrow_down_16x16
  • (use & args)
Like 'require, but also refers to each lib's namespace using
clojure.core/refer. Use :use in the ns macro in preference to calling
this directly.

'use accepts additional options in libspecs: :exclude, :only, :rename.
The arguments and semantics for :exclude, :only, and :rename are the same
as those documented for clojure.core/refer.

3 Examples top

  • ;; Use the namespace clojure.java.io:
    user=> (use '(clojure.java io))
    
    
  • ;; Imports only the split function from clojure.string.
    user=> (use '[clojure.string :only (split)])
    nil
    
    ;; split is now available without a namespace qualification.
    user=> (split "hello world" #" ")
    ["hello" "world"]
    
    ;; You can also add the :as keyword to import the rest of clojure.string
    ;; with a namespace qualification.
    user=> (use '[clojure.string :as s :only (split)])
    nil
    
    ;; Now we can access any function in clojure.string using s.
    user=> (s/replace "foobar" "foo" "squirrel")
    "squirrelbar"
    
    ;; And we can still call split with or without the s qualification.
    user=> (split "hello world" #" ")
    ["hello" "world"]
    user=> (s/split "hello world" #" ")
    ["hello" "world"]
  • (ns some.namespace
      (:require [clojure.contrib.json :as json])
      (:use [clojure.string :only [trim lower-case split]]
            [clojure.contrib.shell-out]
            [clojure.pprint]
            [clojure.test]))
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:5354 top

(defn use
  "Like 'require, but also refers to each lib's namespace using
  clojure.core/refer. Use :use in the ns macro in preference to calling
  this directly.

  'use accepts additional options in libspecs: :exclude, :only, :rename.
  The arguments and semantics for :exclude, :only, and :rename are the same
  as those documented for clojure.core/refer."
  {:added "1.0"}
  [& args] (apply load-libs :require :use args))
Vars in clojure.core/use:
Used in 0 other vars

Comments top

No comments for use. Log in to add a comment.