You're viewing version 1.2.0 of import. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

import

clojure.core

  • (import & import-symbols-or-lists)
import-list => (package-symbol class-name-symbols*)

For each name in class-name-symbols, adds a mapping from name to the
class named by package.name to the current namespace. Use :import in the ns
macro in preference to calling this directly.

3 Examples top

  • user=> (import java.util.Date)
    java.util.Date
    
    user=> (def *now* (Date.))
    #'user/*now*
    
    user=> (str *now*)
    "Tue Jul 13 17:53:54 IST 2010"
    
  • ;; Multiple imports at once.
    (import '(java.util Date Calendar)
            '(java.net URI ServerSocket)
            java.sql.DriverManager)
  • ;; importing multiple classes in a namespace
    (ns foo.bar
      (:import (java.util Date
                          Calendar)
               (java.util.logging Logger
                                  Level)))
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/require

    Loads libs, skipping any that are already loaded. Each argument is

  • 0
    clojure.core/use

    Like 'require, but also refers to each lib's namespace using clojur

  • 0
    clojure.core/ns

    Sets *ns* to the namespace named by name (unevaluated), creating it

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2617 top

(defmacro import 
  "import-list => (package-symbol class-name-symbols*)

  For each name in class-name-symbols, adds a mapping from name to the
  class named by package.name to the current namespace. Use :import in the ns
  macro in preference to calling this directly."
  {:added "1.0"}
  [& import-symbols-or-lists]
  (let [specs (map #(if (and (seq? %) (= 'quote (first %))) (second %) %) 
                   import-symbols-or-lists)]
    `(do ~@(map #(list 'clojure.core/import* %)
                (reduce (fn [v spec] 
                          (if (symbol? spec)
                            (conj v (name spec))
                            (let [p (first spec) cs (rest spec)]
                              (into v (map #(str p "." %) cs)))))
                        [] specs)))))
Vars in clojure.core/import: conj defmacro fn into let list map name reduce str symbol? concat seq
Used in 3 other vars defrecord deftype definterface

Comments top

1 comment(s) for import.

Good description of use/require/import here:

http://blog.8thlight.com/articles/2010/12/6/clojure-libs-and-namespaces-require-use-import-and-ns

Log in to add a comment.