Clojure Namespace Declarations: As Simple As Possible

August 12, 2013 — < 1 minute long

This is all you need to know about Clojure’s namespace declarations:

( ns my-project.core ; :require Clojure libs ( :require clojure.core.async [ compojure.core :refer [ POST routes ]] [ compojure.handler :refer :all ] [ ring.adapter.jetty :as jetty ] [ clojure.edn :as edn :refer [ read ]]) ; :import for Java classes ( :import java.net.Socket java.net.SocketException ))

(If you don’t really know what these are doing, read Colin Jones’s helpful article.)

Combine :require with :as , :refer , and :all to load Clojure libs. Just use :import to load Java classes. This is all you need to know to declare namespaces effectively.

P.S. ClojureScript’s ns is a little special.

This and other works on this site are licensed under a Creative Commons Attribution-Share Alike license.