Created
December 1, 2011 16:52
-
-
Save sneeu/1418151 to your computer and use it in GitHub Desktop.
Importing in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As `require.clj` above. | |
(ns project | |
(:require clojure.string | |
[clojure.set :as set])) | |
# As `use.clj` above. | |
(ns project | |
(:use clojure.string | |
[clojure.set :only [intersection]])) | |
# When using `ns`, quoting isn't required. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `require` namespaces imports but namespaced. | |
(require 'clojure.string ['clojure.set :as 'set]) | |
(def fields | |
(set | |
(clojure.string/split "Name,Email,Password" #","))) # `split` is namespaced. | |
(set/intersection #{"Email" "Password" "DOB"} fields) # `intersection` is namespaced to an alias. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `use` imports everything into the current namespace, this could mangle it, for example string, and set both have a `join` function. | |
(use 'clojure.string '[clojure.set :only [intersection]]) | |
(def fields | |
(set | |
(split "Name,Email,Password" #","))) # `split` from `clojure.string`. | |
(intersection #{"Email" "Password" "DOB"} fields) # `intersection` from `clojure.set`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment