Use functions in other namespace with require
and use
Now we have a 2-dimensional vector glider(as follows) in our own namespace. We want use clojure.pprint/pprint to print it out.
(def glider (vec (repeat 3 (vec (repeat 6 nil)))))
Declare required namespaces:
(def glider (vec (repeat 3 (vec (repeat 6 nil)))))
(require 'clojure.pprint)
(clojure.pprint/pprint glider)
(require '[clojure.data.json :as json])
(defn get-data [url] (json/read-str (slurp url)))
Put required ns in namespace declaration:
(ns conways-game-of-life.core (:require clojure.pprint))
(def glider (vec (repeat 3 (vec (repeat 6 nil)))))
(clojure.pprint/pprint glider)
Give required namespace a alias name:
(ns conways-game-of-life.core (:require [clojure.pprint :as ppr]))
(def glider (vec (repeat 3 (vec (repeat 6 nil)))))
(ppr/pprint glider)
(ns sonar-parser.core
(:require [clojure.data.json :as json]))
(defn get-data [url] (json/read-str (slurp url)))
Use functions in another namespace without prefix:
(ns zap.core
(:use compojure.core)
(:require [compojure.route :as route]
[compojure.handler :as handler]
[ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.params :refer [wrap-params]]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[clojure.data.json :as json]
[zap.views :as views]
[zap.models :as models]))
See full codes on github.
Ref: http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html