Skip to content

clojure.core/ns

View this page on ClojureDocs

Type: macro Added: Clojure 1.0 Examples: 13 Runnable: 3
([name docstring? attr-map? references*])

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

by devijvers on . May have evaluation errors.
by belun on . May have evaluation errors.
by belun on . May have evaluation errors.
by remleduff on
by remleduff on . May have evaluation errors.
by boxie on . May have evaluation errors.
by scode on . May have evaluation errors.
by gstamp on . May have evaluation errors.
by devn on . May have evaluation errors.
by PetrGlad on . May have evaluation errors.
by thescalaguy on . May have evaluation errors.
by mars0i on
by green-coder on

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


Content from the matching ClojureDocs page, with authors credited on each contribution.