clojure.core/ns¶
Sets ns to the namespace named by name (unevaluated), creating it if needed. references can be zero or more of: (:refer-clojure ...) (:require ...) (:use ...) (:import ...) (:load ...) (:gen-class) with the syntax of refer-clojure/require/use/import/load/gen-class respectively, except the arguments are unevaluated and need not be quoted. (:gen-class ...), when supplied, defaults to :name corresponding to the ns name, :main true, :impl-ns same as ns, and :init-impl-ns true. All options of gen-class are supported. The :gen-class directive is ignored when not compiling. If :gen-class is not supplied, when compiled only an nsname__init.class will be generated. If :refer-clojure is not used, a default (refer 'clojure.core) is used. Use of ns is preferred to individual calls to in-ns/require/use/import:
(ns foo.bar (:refer-clojure :exclude [ancestors printf]) (:require (clojure.contrib sql combinatorics)) (:use (my.lib this that)) (:import (java.util Date Timer Random) (java.sql Connection Statement)))
Examples¶
Note by gstamp¶
Good description of use/require/import here:
http://blog.8thlight.com/articles/2010/12/6/clojure-libs-and-namespaces-require-use-import-and-ns
Note by finalfantasia¶
How to ns -- Stuart Sierra’s Opinionated Style Guide for Clojure Namespace Declarations
Make it look like this:
(ns com.example.my-application.server "Example application HTTP server and routing." (:refer-clojure :exclude [send]) (:require [clojure.core.async :as async :refer [<! <!! >! >!!]] [com.example.my-application.base] [com.example.my-application.server.sse :as server.sse] [io.pedestal.http :as http] [io.pedestal.http.sse :as http.sse] [ring.util.response :as response]) (:import (java.nio.file Files LinkOption) (org.apache.commons.io FileUtils)))
Note by matasaru¶
The post referred in the first note has moved to:
https://8thlight.com/insights/clojure-libs-and-namespaces-require-use-import-and-ns
See also¶
- clojure.core/use (1)
- clojure.core/require (4)
- clojure.core/refer (1)
- clojure.core/import (2)
- clojure.core/ns-publics (1)
- clojure.core/in-ns (0)
- clojure.core/remove-ns (0)
- clojure.core/ns-map (1)
- clojure.core/*ns* (0)
- clojure.core/alias (2)
Content from the matching ClojureDocs page, with authors credited on each contribution.