Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Namespace
- (ns learnclojure)
- Types
- (type 1)
- (type 1.1)
- (type true)
- (type "Hello")
- (type (keyword "a"))
- (type (quote a))
- (type 'a)
- (type (list 1 2 3))
- (type (vector 1 2 3))
- (nth (vector 1 2 3) 2)
- (last (list 1 2 3))
- List
- (type (list 1 2 3))
- (type (vector 1 2 3))
- Map
- {:a 1 :b 1 :c 1} {:a 1, :b 1, :c 1}
- (hash-map :a 1 :b 1 :c 1)
- Set
- {type #{1 2 3}}
- (hash-set 1 2 3)
- =========================================================
- Control Flow
- //define var with value
- (def x "Hello")
- (if (empty? x)
- "x is empty"
- "x is not empty")
- (if (empty? x)
- nil
- (do
- (println "ok")
- :ok))
- (if-not (empty? x)
- (do
- (println "ok")
- :ok))
- (when (not (empty? x)) :ok)
- (case x
- "Goodby": goodbye
- "Hi": hello
- :nothing)
- (cond
- (= x "Goodbye") :goodbye
- (- (reverse x) "olleH") :olleh
- :otherwise :nothing)
- ==============================================
- Functions
- (def hello (fn [] "Hello"))
- (hello)
- #(str "Helo)
- (defn hello [] "Hello")
- (defn hello [name] (str "Hello, " name))
- (defn hello "Greets a person named <name> with their <title>" [name, title] (str "Hello, " title " " name))
- (require '[clojure.repl :refer [doc]])
- (doc hello)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement