Skip to content

Instantly share code, notes, and snippets.

@mikechau
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save mikechau/fd8c5a4912d51ec82398 to your computer and use it in GitHub Desktop.

Select an option

Save mikechau/fd8c5a4912d51ec82398 to your computer and use it in GitHub Desktop.
clojure notes
(defn hello [name] (str "Hello, " name))
defn - function
hello - function name
hello - takes one argument, name
str - is a function call that concatenates an arbitrary list of arguments into a string
defn, hello, name, and str are all symbols
;; {}
;; Conjoin, build a new collection
(conj coll item)
(conj #{} "Mike")
;; Atom
(atom initial-state)
;; Name Atom
(def symbol initial-value?)
(def visitors (atom #{}))
;; Update Ref
(swap! r update-fn & args)
(swap! visitors conj "Mike")
;; Refs
(deref visitors)
@visitors
;; require a library
(require quoted-namespace-symbol)
(require 'clojure.java.io)
;; refer namespace to call libs directly
(refer `examples.introduction)
;; require and refer together
(use quoted-namespace-symbol)
(use 'examples.introduction)
(take 10 fibs)
;; reload, force library to reload
(use :reload 'examples.introduction)
a - a Java array
agt - an agent
coll - a collection
expr - an expression
f - a function
idx - index
r - a ref
v - a vector
val - a value
reserved: ref, agent, count
number -> 42
vector -> [1 2 3]
list -> (+ 1 3) -> 4
boolean - true, false
character - \a
keyword - :tag, :doc
list - (1 2 3), (println "foo")
map - {:name "Bill", :age 42}
nil - nil
number - 1, 4.2
set - {:snap, :crackle, :pop}
string - "hello"
symbol - user/foo, java.lang.String
vector - [1 2 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment