Last active
August 29, 2015 14:08
-
-
Save mikechau/fd8c5a4912d51ec82398 to your computer and use it in GitHub Desktop.
clojure notes
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
| (defn hello [name] (str "Hello, " name)) |
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
| 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 |
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
| ;; {} | |
| ;; 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 |
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 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) |
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
| 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 |
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
| 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