Skip to content

Instantly share code, notes, and snippets.

@mikeflynn
Created June 8, 2012 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeflynn/2896209 to your computer and use it in GitHub Desktop.
Save mikeflynn/2896209 to your computer and use it in GitHub Desktop.
;; Namespaces, Symbols, and Vars (Oh, My!) -- @craigandera
;; require = "load"
;; dots => slashes, dash => underscore in require to file
(require '[net.cgrand.enlive-html :as html]) ...you can alias by passing the list elements as sequence.
;; * Single quoting above sequence the reading of the sequence as evaluating happens.
(ns some.name)
;; #'some.name/foo => access var
(def foo)
;; ------
;; refer allows you to add a link to another namespace in the current namespace.
(require '[net.cgrand.enlive-html :as html])
(ns some.where)
(refer 'net.cgrand.enlive-html)
(render ...) ;; This var is from the net.cgrand.enlive-html namespace
;; You can control what from the referred namespace, by using a sequence
(refer '[blah.whatever :only (foo bar)])
;; ------
;; "use" is require + refer
;; use in-in to switch namespaces
;; *ns* var refers to current namespace
;; namespaces by default, are empty. You need "refer" things in to your new namespace.
;; the ns macro auto refers clojure core and java.lang
(ns foo.bar
(:refer-clojure :exclude [replace])
(:require clojure.test)
(:use [clojure.string :only (replace join)]
[clojure.repl :rename {dir ls}])
(:import (java.util Date Timer Random)
java.sql.Connection))
(ns hello
(:require [clojure.string :as str]))
(defn -main [& args]
(println "hello" (str/join " and " args)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment