(operator operand1 operand2 ... operandn)
(str "you say goodbye" "...and I say hello!")
(+ 1 2)
(map inc [1 2 3 4])(if condition
(statement for true)
(statement for false) ;; can be ommited, in which case returns nil if falsey(when true
(first line of the block
second line
.
.
.
n lines for the blocks)){:name "Rodrigo :age 21} ;; create a hash-map literal
(hash-map :name "Rodrigo" :age 21) ;; create a hash-map through the hash-map function(get {:a 1 :b 2} :b) ;; => 2
(get {:a 1 :b {:c 2 :d 3}} :b) ;; => {:c 2 :d 3}
(get (get {:a 1 :b {:c 2 :d 3}} :b) :c) ;; => 2
(get-in {:a 1 :b {:c 2 :d 3}} [:b :c]) ;; => 2(get {:a 1} :c) ;; => nil (for non-existent key)
(get {:a 1} :c "unicorns?") ;; => "unicorns?" (default value)[1 2 3] ;; => [1 2 3] creates a vector literal
(vector 1 2 3) ;; [1 2 3] creates a vector through the vector function
(vector [1 {a: "opa" b: 1/2} "da string" 23/39]) ;; => [1 {a: "opa" b: 1/2} "da string" 23/39] a vector accepts any type(get [25 35 300] 0) ;; => 1 (0th element)
(get [25 35 300] 2) ;; => 300 (2nd element)
(get [25 35 300] 3) ;; => nil (there's no 3rd element)
([25 35 300] 0) ;; => 1 (0th element)
([25 35 300] 3) ;; => throws IndexOutOfBoundsException (different behaviour from `(get [25 35 300] 3)`)(conj [1 2 3] 4 5 6) ;; => [1 2 3 4 5 6] (elements are added at the end of the vector)'(1 2 3 4) ;; => (1 2 3 4) creates a list literal
(list 1 :simbolo {:name "Cartman" :age 7} 1/2) ;; => (1 :simbolo {:name "Cartman" :age 7} 1/2) creates a list(nth '(1 2 3 4) 0) ;; => 1
(nth '(1 2 3 4) 4) ;; => throws IndexOutOfBoundException(conj '(1 2 3) 4 5 6) ;; => (6 5 4 1 2 3) (elements are added at the beginning of the list)For a nubie (as I am), the rule of thumb is: use a
listwhen you need to addelementsat the beginning of asequence. Or when you write amacro. Otherwise, usevector. Daniel Higginbotham - Clojure for the Brave and True
Sets are collections of unique elements.