-
Star
(372)
You must be signed in to star a gist -
Fork
(70)
You must be signed in to fork a gist
-
-
Save ghoseb/287710 to your computer and use it in GitHub Desktop.
| ;; | |
| ;; NS CHEATSHEET | |
| ;; | |
| ;; * :require makes functions available with a namespace prefix | |
| ;; and optionally can refer functions to the current ns. | |
| ;; | |
| ;; * :import refers Java classes to the current namespace. | |
| ;; | |
| ;; * :refer-clojure affects availability of built-in (clojure.core) | |
| ;; functions. | |
| ;; | |
| ;; Updated: 12/09/2016 ~ghoseb | |
| (ns foo.bar | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Refers clojure.string into current NS, e.g.: | |
| ;; (clojure.string/lower-case "FooBar) | |
| (:require [clojure.string]) | |
| ;; Refers string into current NS, e.g.: | |
| ;; (string/lower-case "FooBar") | |
| (:require [clojure.string :as string]) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Refers all functions from clojure.string and | |
| ;; clojure.set into current NS, e.g.: | |
| ;; (union #{:a :b} #{:a :c} #{:b :d}) | |
| ;; (lower-case "FooBar") | |
| (:require [clojure.string :refer :all] | |
| [clojure.set :refer :all]) | |
| ;; Refers only lower-case and union into current NS, e.g.: | |
| ;; (union #{:a :b} #{:a :c} #{:b :d}) | |
| ;; (lower-case "FooBar") | |
| (:require [clojure.string :refer [lower-case]] | |
| [clojure.set :refer [union]]) | |
| ;; Refers ancestors & descendants into current NS as xml-ancestors & xml-descendants | |
| (:require clojure.data.zip) | |
| (:refer [clojure.data.zip :rename {ancestors xml-ancestors, | |
| descendants xml-descendants}]) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Refers ArrayList and HashMap into current NS: | |
| (:import [java.util ArrayList HashMap]) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Excludes built-in print | |
| (:refer-clojure :exclude [print]) | |
| ;; Excludes all built-ins except print | |
| (:refer-clojure :only [print]) | |
| ;; Renames built-in print to core-print | |
| (:refer-clojure :rename {print core-print}) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Reload all dependencies while loading the ns | |
| (:require [clojure.string :as cs :refer [split join]] :reload) | |
| ;; Be verbose about loading the deps | |
| (:require [clojure.string :as cs :refer [split join]] :verbose) | |
| ;; There is also :reload-all that reloads every depenency in the ns | |
| (:require [clojure.string :refer [split join]] :reload-all) | |
| ;; Everything together | |
| (:require [clojure.string :as cs :refer [split join]] :verbose :reload)) |
Hmm. On "what means (:require [io.pedestal.service.http.route.definition :refer [defroutes]]) ", I got two hypotheses :
- (:require [io.pedestal.service.http.route.definition])
(:use [io.pedestal.service.http.route.definition :only [defroutes]]) - (:use [io.pedestal.service.http.route.definition :only [defroutes]])
Don't know which would be right :/ if any ;)
I think I got it.
On the pedestal tutorial, http://pedestal.io/documentation/connecting-to-datomic/
I found :
(:require [datomic.api :as d :refer (q)]))
where we get access to every function by prefixing d/ in front of it. Except for the q function that we can access directly, thanks to :refer.
:)
I suggest adding the following as the combination of :only and :rename:
;; Refers sqrt into current NS as ccm-sqrt, other math functions are not
;; refered, e.g.
;; (ccm-sqrt 4)
[:use [clojure.contrib.math :only [sqrt] :rename {sqrt ccm-sqrt}]]@cmpitg as far as I know :use is deprecated.
:refer lets you use the function without the namespace qualifier.
(ns wawa
(:require [datomic.api :as d :refer [q]]))
(= (d/q args) (q args) (datomic.api/q args) )
Awesome. I never get this right.
In my case, i need to set require with refering to some function, but already have that name bounded to another func(addevent). It's was too straightforward for me to be assume immediately.
(ns project.handler.addevent
(:require
[project.view.pages :refer [addevent] :rename {addevent addevent-page}))
thanks bro greetings get to know
What is the meaning of :refer in the following :
(:require [io.pedestal.service.http.route.definition :refer [defroutes]]
thanks!