Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created December 1, 2011 16:52
Show Gist options
  • Save sneeu/1418151 to your computer and use it in GitHub Desktop.
Save sneeu/1418151 to your computer and use it in GitHub Desktop.
Importing in Clojure
# 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.
# `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.
# `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