Created
June 8, 2012 15:37
-
-
Save mikeflynn/2896209 to your computer and use it in GitHub Desktop.
This file contains 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
;; 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